raduprv / Eternal-Lands

http://www.eternal-lands.com
Other
157 stars 57 forks source link

Mouse and map window accuracy #150

Closed gamil-zirak closed 2 years ago

gamil-zirak commented 2 years ago

In pull request #149 I'm attempting to fix some issues that are bothering me in the map window.

I'm assuming that the map positions are numbered from 0 to (tile_map_size * 6) - 1. For example on a 96x96 map the positions range from 0-95 in both directions. This agrees with what the game compass shows and also the map editor.

In interface.c and map.c, the code doesn't allow a marker on x position 0. I don't see any harm in allowing it so I removed that limitation.

In interface.c: Map markers, destination markings, and current position markings are showing away from the actual mouse position on the map window. They're close but too far for my liking. This is especially noticeable on the smaller 96x96 maps. Rather than drawing the marker relative to the position square's edges, I shifted them so they're relative to the position square center. In other words, I shifted the markers by half a position length. This way the markers and the click-to-walk destination are closer to the mouse position when clicked.

In the pf_get_mouse_position_extended function in pathfinder.c if the mouse cursor is on the right or bottom edge of the map it was setting an extra position. For example in a 96x96 map, it would set px or py to 96 and this would show up as a cursor position on the map. The change limits the max position to 95 on a 96x96 map. Also, the py value was being calculated by subtracting from tile_y*6 but this was causing the vertical position to be off by 1 from the map. For example, using the mouse to hover over the map, it shows cursor positions from 1 to 96 in the vertical direction. Subtracting 1 from this value corrects this problem.

gvissers commented 2 years ago

I apologise for taking so long to get back to you.

These changes look reasonable, and from a quick test, I have to agree that the positions seem to be in better agreement with the map, at least on IP. I have a couple of quick questions:

gamil-zirak commented 2 years ago
* You add half a tile to the tile coordinates to get the center of the mark, which  I understand. ~But the client already seems to try to correct for this half tile by using asymmetric coordinates: from (x-9 * mapmark_zoom, y-9 * mapmark_zoom) to  (x-6  * mapmark_zoom, y-6 * mapmark_zoom) .~ That just seems wrong, now the center coordinates depend on the mapmark zoom factor. Can you check how it looks when you draw the crosses symmetrically around (x, y)?

Using asymmetric mapmark_zoom scales (6 and 9) does affect the center of where the marker is drawn but only slightly. I had played around with various values and using 7 and 7 rather than 6 and 9 this only shifts the center of the marker by a pixel or 2 which is hardly noticeable. Actually I was confused by the asymmetry because it actually was making the markings less accurate in the x direction but I noticed it less after my change. I changed the scale to 7 and 7 as that keeps the marker size very close to before.

* In delete_mark_on_map_on_mouse_position() should 1 be subtracted from my, as you did in pf_get_mouse_position_extended(). Perhaps it doesn't matter too much, as it finds the nearest mark, but I like consistency :) I don't think there are other places like this, but I have not checked all that thoroughly.

Yes, absolutely. It actually does matter if you have 2 marks next to each other in the y direction. I changed this too.

* do the continent maps need adjusting? Perhaps not, the difference may be too small to see, but I thought I'd check.

I thought of this too but I don't see the same issue presently. In fact, the continent map markers already seem to be slightly right and up from the tab map so applying the fix would not help. Anyway any of this is barely noticeable.

gvissers commented 2 years ago

Thanks a lot, I've pulled your changes in.