-
Notifications
You must be signed in to change notification settings - Fork 102
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
Flatten tiles to vec u32 #58
Conversation
* Create TilesContainer for ease of use * Provide some means to easily convert to Vec Vec u32 * Override [], use as [row][column]
* added number_of_rows field
Sorry for the delay, I'll try and look at this at the weekend! |
Sorry for the delay again. Life got in the way I'm afraid :( It looks good. I'm not too bothered about the breaking version as we're still <1.0 (and I doubt anyone is seriously using the library) but maybe we could add a conversion from TilesContainer to Vec<Vec<_>> |
Hey, I've tried looking into this conversion, and it seems to me that we could add a generic one for Vec<Vec>, but it will require a wrapper struct to work properly. Something along those lines:
I'm not exactly sure if this is something desirable in this case. We could just go with implementing the conversion manually for all built in numeric types, but it would produce a lot of boilerplate code. I'm open to any suggestions on how we could improve this solution. |
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.
@satrix321 This seems like a good change to make. Would you still be able to rebase this change to resolve the conflicts? I've also left some comments.
pub struct TilesContainer { | ||
pub data: Vec<u32>, | ||
pub tiles_per_row: u32, | ||
pub number_of_rows: u32, |
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.
Maybe just width
and height
would do as property names?
pub number_of_rows: u32, | ||
} | ||
|
||
impl From<&TilesContainer> for Vec<Vec<u32>> { |
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.
I don't think we need this converter. What use would people have for converting to this sub-optimal data structure? Maybe instead it could be useful to provide a getter to retrieve a tile given x
and y
coordinates?
@@ -653,7 +678,11 @@ impl Layer { | |||
], | |||
TiledError::MalformedAttributes("layer must have a name".to_string()) | |||
); | |||
let mut tiles = Vec::new(); | |||
let mut tiles = TilesContainer { |
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.
Could this be initialized with correct data from the start? I feel like this could lead to invalid states where the tiles member never got initialized.
} | ||
return Ok(rows); | ||
let data: Vec<u32> = s | ||
.replace('\r', "") |
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.
I think trim
after split
would work here.
Superseded by #128. |
Hi,
This change flattens the tiles from a layer into a structure containing Vec (instead of Vec<Vec>) for performance concerns. There's also a method provided for easy conversion to Vec<Vec> if there would be need for it.
As of now this is a breaking change, but with some minor adjustments users would still be able to iterate over this collection by rows (by using tiles_per_row and number_of_rows). I'm open to any suggestions how we could smooth this out a bit more.