DarkflameServer/dGame/dCinema/Play.cpp
wincent cdc9dda3c4 dCinema improvements
* Visiblity and effect records
* Recorder will catch effects from behaviors
* Documentation for setting up a scene to play automatically.
* Documentation for server-side preconditions.
2023-10-29 17:37:26 +01:00

92 lines
1.6 KiB
C++

#include "Play.h"
#include "Scene.h"
#include "EntityManager.h"
using namespace Cinema;
void Cinema::Play::Conclude() {
auto* player = Game::entityManager->GetEntity(this->player);
if (player == nullptr) {
return;
}
scene->Conclude(player);
}
void Cinema::Play::SetupCheckForAudience() {
if (m_CheckForAudience) {
return;
}
m_CheckForAudience = true;
CheckForAudience();
}
void Cinema::Play::CheckForAudience() {
auto* player = Game::entityManager->GetEntity(this->player);
LOG("Checking for audience");
if (player == nullptr) {
CleanUp();
return;
}
if (scene->IsPlayerInBounds(player)) {
SignalBarrier("audience");
m_PlayerHasBeenInsideBounds = true;
}
if (!scene->IsPlayerInShowingDistance(player)) {
if (m_PlayerHasBeenInsideBounds) {
Conclude();
}
CleanUp();
return;
}
// Still don't care
Game::entityManager->GetZoneControlEntity()->AddCallbackTimer(1.0f, [this]() {
CheckForAudience();
});
}
void Cinema::Play::CleanUp() {
LOG("Cleaning up play with %d entities", entities.size());
for (const auto& entity : entities) {
Game::entityManager->DestroyEntity(entity);
}
}
void Cinema::Play::SetupBarrier(const std::string& barrier, std::function<void()> callback) {
// Add the callback to the barrier
if (m_Barriers.find(barrier) == m_Barriers.end()) {
m_Barriers[barrier] = std::vector<std::function<void()>>();
}
m_Barriers[barrier].push_back(callback);
}
void Cinema::Play::SignalBarrier(const std::string& barrier) {
if (m_Barriers.find(barrier) == m_Barriers.end()) {
return;
}
for (const auto& callback : m_Barriers[barrier]) {
callback();
}
m_Barriers.erase(barrier);
}