-
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
Add SFML example #133
Add SFML example #133
Conversation
Adds a rough demo using SFML for rendering.
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.
Works fine! Though we really need a nicer example map I guess. :-)
I've left a number of comments, most of which I'll also address by pushing my changes to the example, but let me know if you disagree about any of them.
It took me a bit to figure out the dependencies to install. In the end I had to install libcsfml-dev
, libsfml-dev
, build-essential
(not entirely sure) and clang
before it would work. Probably something we need to document somewhere.
Hmm, so I've already addressed most of my comments, since I anyway wanted to make sure the changes made sense, given that I'm still learning Rust. However, it appears I can't push to your branch. I've pushed the change here instead: bjorn@b547ffa |
The sfml crate is supposed to vendor its own version of sfml, but for some reason still requires those packages as dependencies. I've had issues with that as well in the past, I'll create an issue in the sfml-rs repo. |
Hmm, according to their documentation they expect you to just install SFML and a suitable compiler first. |
See this PR. I don't think that should apply any more, at least on master. (0.16 does not vendor CSFML). |
I just realized that the autobuild is failing because of the SFML dependency, even though actually it is only used by one of the examples, which isn't actually being compiled. Is there any way to make this dependency only install when trying to compile that example? |
@alexdevteam Would you mind allowing me to push into your branch (the pull request setting), so that I could just push bjorn@b547ffa? |
Sure, but I can't find the option :( |
It should be exactly there, so not sure why you can't see it. Maybe you could just cherry-pick this change for now. |
Okay there we go, for some reason the setting isn't visible if the repo is in an organization. Moved it to my account and now you should be able to push changes just fine. |
Ah, ok! So, that was what the "On user-owned forks" in the docs was about. That wasn't exactly standing out, heh. |
* Rely on sfml 0.16 rather than a git revision * Avoid allocating temporary Path * Take into account margin and spacing * Directly produce a FloatRect, since it is what SFML needs * Renamed VertexMesh to QuadMesh * Use Vertex::with_pos_coords since we always passed Color::WHITE * Removed TileLayer wrapper, since it added no value * Removed handling of gid == 0 in Tilesheet::tile_rect
Also fixes the example a bit, because the map was drawn too small.
If there is no way to do this, I would be fine with adding the installation of |
This is strange. Build is failing as if it the crate modules were private. |
Alright, fixed, that should do it for the CI. We now have two workflows; One for the library and one for the SFML example. The SFML example one only should run when there has been some change in the examples/sfml directory. |
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.
Looks fine to me! I'm not really sure about splitting off the build for the SFML example though, since we'd want to make sure it compiles also when making changes to the library anyway.
Thanks for this example, it's been a great boost to get going with tiled quickly. I've just got a minor suggestion to improve usability: - let map = Map::parse_file(Path::new(MAP_PATH)).unwrap();
+ let mut path = std::fs::canonicalize(".").expect("current dir does not exist");
+ path.push("assets");
+ while !path.exists() {
+ path.pop();
+ if !path.pop() {
+ println!("ERROR: reached file-system root without finding the assets directory");
+ return
+ }
+ path.push("assets");
+ }
+ path.pop();
+ let map = Map::parse_file(path.join(MAP_PATH)).unwrap(); Something like this to allow the example to be run from any directory within the project. Makes it easier to poke around with the example if (like me) you want to use it to understand how rs-tiled works. Happy to PR this myself once this is merged if you'd prefer. |
Thanks for trying out the example @G-0-0, and I'm glad it helped you! Regarding your patch, I'm not sure this approach sets a good example. First of all I'd like to know, how were you running the example? Normally I'd expect people to execute I've also taken a look at how Bevy finds assets, and they use the |
Have to agree with @bjorn here. Right now my priority with this PR is to get the lowest amount of boilerplate possible, so adding code like that wouldn't show anything to the end user about the library, and furthermore, I expect this code to be run with cargo. As such, I don't think it's appropriate to use it. However, I could replace the |
Thanks both for the responses.
I am running this with cargo:
Anyway, my intention wasn't to stop this getting merged, so please go ahead and I can address this afterwards. Also I wasn't aware of that method of finding the executable path, so thanks for sharing the Bevy example, it's a lot nicer. |
Ah, so, in case you were not aware, you don't need to |
That should fix it. |
A few TODOs for this PR:
|
Merging is blocked by #135. |
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.
This is looking pretty good now I think. Is there a reason the PR is still marked as Draft?
I'd like a prettier map to show instead of the one we have now. |
let mut mesh = QuadMesh::with_capacity(width * height); | ||
for x in 0..width { | ||
for y in 0..height { | ||
// TODO: `FiniteTileLayer` for getting tiles directly from finite tile layers? |
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.
Also: This right here
Alright, but I think that could be better as a separate change. It's alright to reuse one of the ugly example maps for now and improve that later. Regarding support for infinite maps, I also don't think it's required for now, especially since the API for this is still not finalized, and the example map used is not infinite anyway. Similarly the example currently doesn't support maps using multiple tilesets, but it's something that can be improved upon later as well. |
Alright, merging then. |
Adds a rough demo using SFML for rendering. Closes #35.
Extremely WIP. Right now the example is really long because a lot of boilerplate is required. If you realize any way to reduce this boilerplate without making the example more specific, let me know.