"""
Example node showing realtime update from gathered data.
"""


class OgnBouncingCubesCpu:
    @staticmethod
    def compute(db):

        velocities = db.state.velocities
        translations = db.state.translations
        # Empty input means nothing to do
        if translations.size == 0 or velocities.size == 0:
            return True

        h = 1.0 / 60.0
        g = -1000.0
        for ii, velocity in enumerate(velocities):
            velocity += h * g
            translations[ii][2] += h * velocity
            if translations[ii][2] < 1.0:
                translations[ii][2] = 1.0
                velocity = -5 * h * g

        translations[0][0] += 0.03
        translations[1][0] += 0.03

        # We no longer need to set values because we do not copy memory of the numpy arrays
        # Mutating the numpy array will also mutate the attribute data
        # Alternative, setting values using the below lines will also work

        # context.set_attr_value(translations, attr_translations)
        # context.set_attr_value(velocities, attr_translations)

        return True
