mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-05 16:07:27 +02:00
Fix saves sometimes being one cell larger than intended
Namely, when any dimension of the underlying particle area is divisible by CELL. Importantly, this includes "normal" saves (as opposed to stamps), which take the entire simulation area, making them impossible to load. Broken byc2bb777212
, where RectBetween(topLeft / CELL, bottomRight / CELL) was rewritten to RectSized(pos / CELL, size / CELL), which is not equivalent. This commit also neglected to add TopLeft() and BottomRight() to Rect. Incorrectly fixed by6a903ed132
, where RectSized(pos / CELL, size / CELL) was rewritten to RectBetween(pos / CELL, (pos + size) / CELL), which is also not equivalent.
This commit is contained in:
@@ -380,6 +380,18 @@ public:
|
||||
return point.X >= pos.X && point.X < pos.X + size.X && point.Y >= pos.Y && point.Y < pos.Y + size.Y;
|
||||
}
|
||||
|
||||
template<typename S = T, typename = std::enable_if_t<std::is_integral_v<S>>>
|
||||
inline Vec2<T> TopLeft() const
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
template<typename S = T, typename = std::enable_if_t<std::is_integral_v<S>>>
|
||||
inline Vec2<T> BottomRight() const
|
||||
{
|
||||
return pos + size - Vec2<T>(1, 1);
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
Rect<decltype(std::declval<T>() + std::declval<S>())> Inset(S delta) const
|
||||
{
|
||||
|
@@ -312,7 +312,7 @@ void Simulation::Load(const GameSave *save, bool includePressure, Vec2<int> bloc
|
||||
|
||||
std::unique_ptr<GameSave> Simulation::Save(bool includePressure, Rect<int> partR) // particle coordinates
|
||||
{
|
||||
auto blockR = RectBetween(partR.pos / CELL, (partR.pos + partR.size) / CELL);
|
||||
auto blockR = RectBetween(partR.TopLeft() / CELL, partR.BottomRight() / CELL);
|
||||
auto blockP = blockR.pos;
|
||||
|
||||
auto newSave = std::make_unique<GameSave>(blockR.size);
|
||||
|
Reference in New Issue
Block a user