void PPlayer::v_updateEntity(entityID id, const GameTime& gameTime) {
    CPlayer *player = getEntityAs<CPlayer>(id);
    CTransform *transform = getEntityAs<CTransform>(id);
    CRigidBody *body = getEntityAs<CRigidBody>(id);

    if (player->m_bAlive) {
        player->m_elapsedTime += gameTime.getElapsedMillisecond();
        double temp = 0.25f * sin((double)(MathUtils::TWO_PI * 0.001 * player->m_elapsedTime + 0));

        // set screen position with floating in account
        player->m_floatingAmount = temp;
        transform->setOffsetY(transform->getOffsetY() + player->m_floatingAmount);

        if (player->m_bSpeedUp) {
            if (player->m_actualThrustAmount < player->m_speedupThrustAmount) {
                player->m_actualThrustAmount += 350 * gameTime.getElapsedSecond();
            }
            player->m_bSpeedUp = false;
        }
        else {
            if (player->m_actualThrustAmount < player->m_maxThrustAmount) {
                player->m_actualThrustAmount += 150 * gameTime.getElapsedSecond();
            }
            else if (player->m_actualThrustAmount > player->m_maxThrustAmount) {
                player->m_actualThrustAmount -= 250 * gameTime.getElapsedSecond();
            }
        }
        
        body->m_velocity.y = sin(transform->getRotation()) * player->m_actualThrustAmount;
        body->m_velocity.x = player->m_forward.x * cos(transform->getRotation()) * player->m_actualThrustAmount;

        if (player->m_cooldown > 0) {
            player->m_cooldown -= gameTime.getElapsedMillisecond();
            // Design issue : Draw with UpdateProcess
            Locator::getRenderer()->renderRectangle(true, transform->getX() - 25, transform->getY() + 55, 75, 5, 0xFF, 0xFF, 0xFF);
            Locator::getRenderer()->renderRectangle(true, transform->getX() - 25, transform->getY() + 55, (1 - (player->m_cooldown / player->m_defaultCooldown)) * 75, 5, 0x66, 0x99, 0x99);
        }
    }
}
void PAnimation::v_updateEntity(entityID id, const GameTime& gameTime) {
    CAnimation *anim = getEntityAs<CAnimation>(id);

    if (anim->m_bActivated) {
        if (anim->m_elapsedTime >= anim->m_frameDuration) {
            anim->m_currentFrame++;
            if (anim->m_currentFrame >= anim->m_animation->get()->getFrameCount()) {
                
                if (anim->m_bLoop == false) {
                    anim->m_bActivated = false;
                } else {
                    anim->m_currentFrame = 0;
                }
            }
            anim->m_elapsedTime = 0;
        }
        else {
            anim->m_elapsedTime += gameTime.getElapsedMillisecond();
        }
    }
}
void PParticuleManager::v_updateEntity(entityID id, const GameTime& gameTime) {
    CParticuleEmitter *e = getEntityAs<CParticuleEmitter>(id);
    CTransform *transform = getEntityAs<CTransform>(id);

    if (e->m_bActive) {
        e->m_elapsedRate += gameTime.getElapsedMillisecond();
        if (e->m_elapsedRate > e->m_rate)  {

            // due to custom memory allocation used by clone method, the pointer could
            // be null sometimes
            IParticule* p = e->m_particulePrototype->cloneIntoPool();
            if (p != nullptr) {

                // TODO : cause a division per zero
                /*float lv = (e->m_lifetimeVariation > 0) ? MathUtils::randint(e->m_lifetimeVariation * 2) - e->m_lifetimeVariation : 0;
                float av = (e->m_angleVariation > 0) ? MathUtils::randint(e->m_angleVariation * 2) - e->m_angleVariation : 0;
                float sv = (e->m_speedVariation > 0) ? MathUtils::randint(e->m_speedVariation * 2) - e->m_speedVariation : 0;
                float pv = (e->m_spawnPositionVariation > 0) ? MathUtils::randint(e->m_spawnPositionVariation * 2) - e->m_spawnPositionVariation : 0;*/
                float lv , av, sv, pv = 0;

                p->m_x = transform->getX() + pv;
                p->m_y = transform->getY() + pv;
                p->m_elapsed = 0;
                p->m_lifetime = e->m_lifetime + lv;
                glm::vec2 velocity = MathUtils::fromPolar(e->m_angle + av, e->m_speed + sv);
                p->m_vx = velocity.x;
                p->m_vy = velocity.y;

                p->m_gravityApplied = e->m_bIsGravityApplied;

                m_particulesEmitted.push_back(p);
            }
            e->m_elapsedRate = 0;
        }
    }
}