Two maxims: Programmers should never repeat themselves...
What did you mean by this?
The code in the first post contains two lines of code that are almost identical. Chances are you can give the operation a good name and put it in a function.
I also recommend writing operations on vectors or points instead of having high-level code do everything component by component.
float snap_to_multiple(float x, float size) {
return std::floor(x / size) * size;
}
Point snap_to_grid(Point p, float tile_size) {
Point result;
result.x = snap_to_multiple(p.x, tile_size);
result.y = snap_to_multiple(p.y, tile_size);
return result;
}
// ...
m_sfSelectedTilePos = snap_to_grid(m_sfEvent.mouseButton, 64.0f);