holesome/src/game/physics/holes/layouts/hole_layout.cpp

48 lines
1 KiB
C++
Raw Normal View History

2023-06-28 16:57:13 +02:00
#include "hole_layout.hpp"
#include "../../../player/player_collection.hpp"
std::shared_ptr<HoleLayout> HoleLayout::getInstance()
{
if (singletonInstance == nullptr)
{
singletonInstance = std::make_shared<HoleLayout>();
}
return singletonInstance;
}
void HoleLayout::clear()
{
previousHoles.clear();
currentHoles.clear();
}
void HoleLayout::lateUpdate()
{
// Move history forward
previousHoles = currentHoles;
currentHoles.clear();
// Collect hole descriptions of active players
for (const auto &player: PlayerCollection::getInstance()->getPlayers())
{
if (player->getActive())
{
currentHoles.emplace_back(player);
}
}
}
HoleLayout::HoleLayout()
: currentHoles(), previousHoles()
{}
DepthHoleLayout HoleLayout::atDepth(float depth) const
{
std::vector<DepthHoleDescription> depthHoles{};
for (const auto &hole: currentHoles)
{
depthHoles.push_back(hole.atDepth(depth));
}
return DepthHoleLayout(depth, depthHoles);
}