#include "server/game/ServerGame.h"

#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
#include "server/Server.h"

namespace blitz {
namespace server {

ServerGame::ServerGame(Server* server) : m_Server(server), m_PositionTimer(SERVER_TPS) {}

ServerGame::~ServerGame() {}

void ServerGame::Tick(std::uint64_t delta) {
	if (m_PositionTimer.Update(delta)) {
		SendPlayerPositions();
	}
}

void ServerGame::SendPlayerPositions() {
	for (const auto& [playerID, player] : GetPlayers()) {
		protocol::PlayerPositionAndRotationPacket packet(player.GetPosition(), player.GetYaw(), player.GetPitch(), playerID);
		m_Server->BroadcastPacket(&packet);
	}
}

}  // namespace server
}  // namespace blitz
