jshuaf / Aquaforces

The land of the free
0 stars 0 forks source link

Add back river reflections. #90

Closed jshuaf closed 7 years ago

jshuaf commented 7 years ago

Okay, so basically we have a problem with these river reflections. The current implementation is killing the CPU and freezing the game very quickly (see #78), so I've disabled them for now.

The current implementation of river reflections (pseudocode):

updateRiverReflections() {
  forEach riverReflection:
    if (justHad correctAnswer) {
      const newPosition = calculatePosition(riverReflection.oldPosition)
      setState({newPosition})
    else {
      // see above, calculate position and set state
    }

    if (riverReflection.isWayOffScreen) remove(riverReflection)
    if (bottomReflectionIsTooHigh) addBottomReflection()
    if (topReflectionIsTooLow) addTopReflection()
}

Basically having to iterate over the whole list of river reflection groups every time and perform some calculations... not to mention dispatching functions that will respectively iterate over the list AGAIN in order to either

So... this obviously can't all happen in the 16ms we get in requestAnimationFrame

alexandernext commented 7 years ago

Maybe we can just switch to images -- but we should talk to designers about this @janisfuh

ssneilss commented 7 years ago

I think using html5 canvas might be a solution? it uses GPU to render (only if the calculation functions don't take too much effort to run for browser I think

jshuaf commented 7 years ago

That would work, but would require a major refactorization as we're currently rendering them as React components. It could get messy to try to coerce the DOM and canvas to work together.

ssneilss commented 7 years ago

yeah true lemme take a look first

alexandernext commented 7 years ago

Would it work if the boat is moving most of the time and the only time the river reflections need to move is when the boat is about to move off the screen, in which case this function is triggered?

jshuaf commented 7 years ago

So you want the boat to move instead of the river reflections?

alexandernext commented 7 years ago

@jshuaf Yeah that makes it a lot easier computationally?

jshuaf commented 7 years ago

hm... it would change the feel of the game a lot. you'd have to deal with a camera

alexandernext commented 7 years ago

@jshuaf let's talk over this at the meeting