Resolved some comments

This commit is contained in:
wincent 2023-11-20 19:52:27 +01:00
parent 32cbd18e6b
commit 17a62d95e0
4 changed files with 41 additions and 34 deletions

View File

@ -6,7 +6,7 @@
using namespace Cinema; using namespace Cinema;
void Cinema::Play::Conclude() { void Play::Conclude() {
auto* player = Game::entityManager->GetEntity(this->player); auto* player = Game::entityManager->GetEntity(this->player);
if (player == nullptr) { if (player == nullptr) {
@ -16,7 +16,7 @@ void Cinema::Play::Conclude() {
scene->Conclude(player); scene->Conclude(player);
} }
void Cinema::Play::SetupCheckForAudience() { void Play::SetupCheckForAudience() {
if (m_CheckForAudience) { if (m_CheckForAudience) {
return; return;
} }
@ -26,7 +26,7 @@ void Cinema::Play::SetupCheckForAudience() {
CheckForAudience(); CheckForAudience();
} }
void Cinema::Play::CheckForAudience() { void Play::CheckForAudience() {
auto* player = Game::entityManager->GetEntity(this->player); auto* player = Game::entityManager->GetEntity(this->player);
if (player == nullptr) { if (player == nullptr) {
@ -51,13 +51,13 @@ void Cinema::Play::CheckForAudience() {
return; return;
} }
// Still don't care // 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]() { Game::entityManager->GetZoneControlEntity()->AddCallbackTimer(1.0f, [this]() {
CheckForAudience(); CheckForAudience();
}); });
} }
void Cinema::Play::CleanUp() { void Play::CleanUp() {
LOG("Cleaning up play with %d entities", entities.size()); LOG("Cleaning up play with %d entities", entities.size());
for (const auto& entity : entities) { for (const auto& entity : entities) {
@ -65,25 +65,23 @@ void Cinema::Play::CleanUp() {
} }
} }
void Cinema::Play::SetupBarrier(const std::string& barrier, std::function<void()> callback) { void Play::SetupBarrier(const std::string& barrier, const std::function<void()>& callback) {
// Add the callback to the barrier // 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); m_Barriers[barrier].push_back(callback);
} }
void Cinema::Play::SignalBarrier(const std::string& barrier) { void Play::SignalBarrier(const std::string& barrier) {
if (m_Barriers.find(barrier) == m_Barriers.end()) { const auto& it = m_Barriers.find(barrier);
if (it == m_Barriers.end()) {
return; return;
} }
for (const auto& callback : m_Barriers[barrier]) { for (const auto& callback : it->second) {
callback(); callback();
} }
m_Barriers.erase(barrier); m_Barriers.erase(it);
} }

View File

@ -60,7 +60,7 @@ public:
* @param barrier The name of the barrier. * @param barrier The name of the barrier.
* @param callback The callback to call when the barrier is signaled. * @param callback The callback to call when the barrier is signaled.
*/ */
void SetupBarrier(const std::string& barrier, std::function<void()> callback); void SetupBarrier(const std::string& barrier, const std::function<void()>& callback);
/** /**
* @brief Signal a barrier. * @brief Signal a barrier.

View File

@ -9,13 +9,31 @@
using namespace Cinema; using namespace Cinema;
std::unordered_map<std::string, Prefab> Prefab::m_Prefabs; struct PrefabInstance
std::unordered_map<size_t, Prefab::Instance> Prefab::m_Instances; {
std::vector<LWOOBJID> m_Entities;
};
namespace {
std::unordered_map<std::string, Prefab> m_Prefabs;
std::unordered_map<size_t, PrefabInstance> m_Instances;
float m_AngleToRadians = 0.0174532925f;
}
size_t Prefab::AddObject(LOT lot, NiPoint3 position, NiQuaternion rotation, float scale) { size_t Prefab::AddObject(LOT lot, NiPoint3 position, NiQuaternion rotation, float scale) {
const auto id = ObjectIDManager::GenerateRandomObjectID(); const auto id = ObjectIDManager::GenerateRandomObjectID();
m_Pieces.emplace(id, Prefab::Piece { lot, position, rotation, scale, {} }); m_Pieces.emplace(id, Prefab::Piece {
lot,
position,
rotation,
scale,
std::vector<int32_t>()
});
return id; return id;
} }
@ -55,9 +73,9 @@ const Prefab& Prefab::LoadFromFile(std::string file) {
// Check if the qx attribute exists, if so the rotation is a quaternion, otherwise it's a vector // Check if the qx attribute exists, if so the rotation is a quaternion, otherwise it's a vector
if (!element->Attribute("qx")) { if (!element->Attribute("qx")) {
rotation = NiQuaternion::FromEulerAngles( { rotation = NiQuaternion::FromEulerAngles( {
element->FloatAttribute("rx") * 0.0174532925f, element->FloatAttribute("rx") * m_AngleToRadians,
element->FloatAttribute("ry") * 0.0174532925f, element->FloatAttribute("ry") * m_AngleToRadians,
element->FloatAttribute("rz") * 0.0174532925f element->FloatAttribute("rz") * m_AngleToRadians
} ); } );
} }
else { else {
@ -141,7 +159,7 @@ size_t Prefab::Instantiate(NiPoint3 position, float scale) const {
// Generate random name // Generate random name
std::string effectName = "Effect_"; std::string effectName = "Effect_";
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
effectName += std::to_string(rand() % 10); effectName += std::to_string(GeneralUtils::GenerateRandomNumber<size_t>(0, 10));
} }
renderComponent->PlayEffect(effect, u"create", effectName); renderComponent->PlayEffect(effect, u"create", effectName);
@ -152,7 +170,7 @@ size_t Prefab::Instantiate(NiPoint3 position, float scale) const {
Game::entityManager->ConstructEntity(entity); Game::entityManager->ConstructEntity(entity);
} }
m_Instances.emplace(id, Prefab::Instance { entities }); m_Instances.emplace(id, PrefabInstance { entities });
return id; return id;
} }

View File

@ -18,6 +18,8 @@ class Prefab
public: public:
Prefab() = default; Prefab() = default;
~Prefab() = default;
/** /**
* @brief Adds an object to the prefab. * @brief Adds an object to the prefab.
* *
@ -87,8 +89,6 @@ public:
static void DestroyInstance(size_t instanceID); static void DestroyInstance(size_t instanceID);
~Prefab() = default;
private: private:
struct Piece struct Piece
{ {
@ -99,16 +99,7 @@ private:
std::vector<int32_t> m_Effects; std::vector<int32_t> m_Effects;
}; };
struct Instance
{
std::vector<LWOOBJID> m_Entities;
};
std::unordered_map<size_t, Piece> m_Pieces; std::unordered_map<size_t, Piece> m_Pieces;
static std::unordered_map<std::string, Prefab> m_Prefabs;
static std::unordered_map<size_t, Instance> m_Instances;
}; };
} }