[DiscordArchive] what about the case of (!cell.NoCreate()) being true ?
[DiscordArchive] what about the case of (!cell.NoCreate()) being true ?
Archived author: jackpoz • Posted: 2023-03-22T20:36:00.744000+00:00
Original source
what about the case of (!cell.NoCreate()) being true ?
Archived author: jackpoz • Posted: 2023-03-22T20:36:42.244000+00:00
Original source
because the body of that if has to handle both cases
Archived author: jackpoz • Posted: 2023-03-22T20:37:51.410000+00:00
Original source
the point of the current code calling EnsureGridLoaded(cell); is that there is 1 case where this is needed, which is when !cell.NoCreate() returns true and IsGridLoaded(GridCoord(x, y) returns false
Archived author: jackpoz • Posted: 2023-03-22T20:38:36.484000+00:00
Original source
ofc, the code could be "optimized" to avoid the EnsureGridLoaded(cell) call in the case !cell.NoCreate() is false and IsGridLoaded(GridCoord(x, y) is true
Archived author: jackpoz • Posted: 2023-03-22T20:41:44.839000+00:00
Original source
https://gist.github.com/jackpoz/4e5b5b25...25acba4b99
```cpp
bool ensure = false, valid = false;
if (!cell.NoCreate())
{
ensure = true;
valid = true;
}
else if (IsGridLoaded(GridCoord(x, y))
{
ensure = false;
valid = true;
}
if (valid)
{
if (ensure)
EnsureGridLoaded(cell);
getNGrid(x, y)->VisitGrid(cell_x, cell_y, visitor);
}
```
Archived author: jackpoz • Posted: 2023-03-22T20:42:12.686000+00:00
Original source
now, not sure if the added complexity and unreadability is really that good
Archived author: jackpoz • Posted: 2023-03-22T20:42:37.079000+00:00
Original source
but I take this is what you wanted ?
Archived author: jackpoz • Posted: 2023-03-22T20:44:02.003000+00:00
Original source
well I guess it can be simplified:
```cpp
bool valid = false;
if (!cell.NoCreate())
{
EnsureGridLoaded(cell);
valid = true;
}
else if (IsGridLoaded(GridCoord(x, y))
{
valid = true;
}
if (valid)
getNGrid(x, y)->VisitGrid(cell_x, cell_y, visitor);
```
Archived author: jackpoz • Posted: 2023-03-22T20:44:36.210000+00:00
Original source
now it doesn't look that bad anymore
Archived author: Gamemechanic • Posted: 2023-03-22T20:55:46.335000+00:00
Original source
```c++
if (!cell.NoCreate())
{
EnsureGridLoaded(cell);
getNGrid(x, y)->VisitGrid(cell_x, cell_y, visitor);
}
else if (IsGridLoaded(GridCoord(x, y))
{
getNGrid(x, y)->VisitGrid(cell_x, cell_y, visitor);
}```
Better or worse?