2023-10-27 21:51:38 +00:00
|
|
|
#include "Play.h"
|
|
|
|
|
|
|
|
#include "Scene.h"
|
|
|
|
|
|
|
|
#include "EntityManager.h"
|
|
|
|
|
|
|
|
using namespace Cinema;
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
void Play::Conclude() {
|
2023-10-27 21:51:38 +00:00
|
|
|
auto* player = Game::entityManager->GetEntity(this->player);
|
|
|
|
|
|
|
|
if (player == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
scene->Conclude(player);
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
void Play::SetupCheckForAudience() {
|
2023-10-27 21:51:38 +00:00
|
|
|
if (m_CheckForAudience) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_CheckForAudience = true;
|
|
|
|
|
|
|
|
CheckForAudience();
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
void Play::CheckForAudience() {
|
2023-10-27 21:51:38 +00:00
|
|
|
auto* player = Game::entityManager->GetEntity(this->player);
|
|
|
|
|
|
|
|
if (player == nullptr) {
|
|
|
|
CleanUp();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2023-10-29 16:37:26 +00:00
|
|
|
|
|
|
|
if (scene->IsPlayerInBounds(player)) {
|
|
|
|
SignalBarrier("audience");
|
|
|
|
|
|
|
|
m_PlayerHasBeenInsideBounds = true;
|
|
|
|
}
|
2023-10-27 21:51:38 +00:00
|
|
|
|
2024-09-08 17:40:08 +00:00
|
|
|
if (!scene->IsPlayerInMaximumShowingDistance(player)) {
|
2023-10-29 16:37:26 +00:00
|
|
|
if (m_PlayerHasBeenInsideBounds) {
|
|
|
|
Conclude();
|
|
|
|
}
|
2023-10-27 21:51:38 +00:00
|
|
|
|
|
|
|
CleanUp();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
// As the scene isn't associated with a specifc objects, we'll use the zone control entity to setup a callback.
|
2023-10-27 21:51:38 +00:00
|
|
|
Game::entityManager->GetZoneControlEntity()->AddCallbackTimer(1.0f, [this]() {
|
|
|
|
CheckForAudience();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
void Play::CleanUp() {
|
2023-10-28 10:28:17 +00:00
|
|
|
LOG("Cleaning up play with %d entities", entities.size());
|
|
|
|
|
2023-10-27 21:51:38 +00:00
|
|
|
for (const auto& entity : entities) {
|
|
|
|
Game::entityManager->DestroyEntity(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
void Play::SetupBarrier(const std::string& barrier, const std::function<void()>& callback) {
|
2023-10-27 21:51:38 +00:00
|
|
|
// Add the callback to the barrier
|
|
|
|
m_Barriers[barrier].push_back(callback);
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
void Play::SignalBarrier(const std::string& barrier) {
|
|
|
|
const auto& it = m_Barriers.find(barrier);
|
|
|
|
|
|
|
|
if (it == m_Barriers.end()) {
|
2023-10-27 21:51:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
for (const auto& callback : it->second) {
|
2023-10-27 21:51:38 +00:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:52:27 +00:00
|
|
|
m_Barriers.erase(it);
|
2023-10-27 21:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|