#include "trace.hpp"

#include <glm/gtx/norm.hpp>

#include "missile.hpp"

#include <iostream>

namespace game {
    Trace::TracePoint::TracePoint(const Missile *missile)
        : position(missile->position)
        , speed(glm::length(missile->velocity))
    {
    }

    Trace::Trace(Missile *missile, float maxAge)
        : missile(missile)
        , player(missile->player)
        , fidelityCounter(0)
        , age(0.0)
        , maxAge(maxAge)
    {
        points.push_back(TracePoint(missile));
    }

    Trace::~Trace()
    {
        //std::cout<<"~Trace()" << std::endl;
    }

    void Trace::addPointFromMissile(bool forceAdd)
    {
        // TODO: make configurable
        fidelityCounter++;
        if (forceAdd || fidelityCounter >= 10) {
            fidelityCounter = 0;
            points.push_back(TracePoint(missile));
        }
    }

    void Trace::finish()
    {
        //std::cout<<"trace finished now!" << std::endl;
        missile = nullptr;
    }
}
