#Calculate first then instantiate vs instantiate as I calculate

1 messages · Page 1 of 1 (latest)

jolly goblet
#

I'm using a Wave Function Collapse algorithm to generate a map using gameobject tiles and I wonder if I should instantiate the tiles in the same loop as I run the WFC or if I should collapse the whole grid first and then instantiate the tiles in a different loop.

Two loops sound expensive, no? But at the same time, it makes the code so much cleaner.

undone lagoon
#

Two loops sound expensive, no?
is it actually doing different amounts of work?

#
for (int i = 0; i < 5; i++) {
  DoX();
}
for (int i = 0; i < 5; i++) {
  DoY();
}
``````cs
for (int i = 0; i < 5; i++) {
  DoX();
  DoY();
}
```both of these do approximately the same work. there is some slight overhead from the loop itself, but that's completely negligible in comparison to whatever task you're actually doing. but there is a difference in behavior, so take that into account too.

consider whether it's a different amount of work (extra lookups? repeated calculations?) and whether the different order of operations makes sense/is correct
jolly goblet