DarkflameServer/dGame/dCinema/Play.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
1.6 KiB
C++
Raw Normal View History

#include "Play.h"
#include "Scene.h"
#include "EntityManager.h"
using namespace Cinema;
2023-11-20 18:52:27 +00:00
void Play::Conclude() {
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() {
if (m_CheckForAudience) {
return;
}
m_CheckForAudience = true;
CheckForAudience();
}
2023-11-20 18:52:27 +00:00
void Play::CheckForAudience() {
auto* player = Game::entityManager->GetEntity(this->player);
if (player == nullptr) {
CleanUp();
return;
}
if (scene->IsPlayerInBounds(player)) {
SignalBarrier("audience");
m_PlayerHasBeenInsideBounds = true;
}
2024-09-08 17:40:08 +00:00
if (!scene->IsPlayerInMaximumShowingDistance(player)) {
if (m_PlayerHasBeenInsideBounds) {
Conclude();
}
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.
Game::entityManager->GetZoneControlEntity()->AddCallbackTimer(1.0f, [this]() {
CheckForAudience();
});
}
2023-11-20 18:52:27 +00:00
void Play::CleanUp() {
LOG("Cleaning up play with %d entities", entities.size());
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) {
// 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()) {
return;
}
2023-11-20 18:52:27 +00:00
for (const auto& callback : it->second) {
callback();
}
2023-11-20 18:52:27 +00:00
m_Barriers.erase(it);
}