diff --git a/dGame/dCinema/Play.cpp b/dGame/dCinema/Play.cpp index c1683692..a71a4cd5 100644 --- a/dGame/dCinema/Play.cpp +++ b/dGame/dCinema/Play.cpp @@ -29,6 +29,8 @@ void Cinema::Play::SetupCheckForAudience() { void Cinema::Play::CheckForAudience() { auto* player = Game::entityManager->GetEntity(this->player); + LOG("Checking for audience"); + if (player == nullptr) { CleanUp(); @@ -50,6 +52,8 @@ void Cinema::Play::CheckForAudience() { } void Cinema::Play::CleanUp() { + LOG("Cleaning up play with %d entities", entities.size()); + for (const auto& entity : entities) { Game::entityManager->DestroyEntity(entity); } @@ -66,7 +70,7 @@ void Cinema::Play::SetupBarrier(const std::string& barrier, std::functionLog("Cinema::Play", "Barrier %s does not exist", barrier.c_str()); + LOG("Barrier %s does not exist", barrier.c_str()); return; } diff --git a/dGame/dCinema/Prefab.cpp b/dGame/dCinema/Prefab.cpp index 6dc5a5ec..c22bf7a1 100644 --- a/dGame/dCinema/Prefab.cpp +++ b/dGame/dCinema/Prefab.cpp @@ -40,7 +40,7 @@ const Prefab& Prefab::LoadFromFile(std::string file) { tinyxml2::XMLElement* root = doc.FirstChildElement("Prefab"); if (!root) { - Game::logger->Log("Prefab", "Failed to load prefab from file: %s", file.c_str()); + LOG("Failed to load prefab from file: %s", file.c_str()); m_Prefabs.emplace(file, prefab); diff --git a/dGame/dCinema/README.md b/dGame/dCinema/README.md index 5cecd613..7a3b8f5e 100644 --- a/dGame/dCinema/README.md +++ b/dGame/dCinema/README.md @@ -14,6 +14,8 @@ Cinema works with a few concepts: ## Play isolation When a play is performed to a player, it is always isolated from the rest of the players in the world. This is to ensure that the player can experience the play without being disturbed by others, and others can't be disturbed by the play. This is achieved by ghosting all NPCs and props in the play to all players except the one experiencing the play. + + ## How to create a scene A play is created is a couple of steps: 1. Acts out the scene in the world as how the NPCs should reenact it. diff --git a/dGame/dCinema/Recorder.cpp b/dGame/dCinema/Recorder.cpp index e877206d..9a8f6036 100644 --- a/dGame/dCinema/Recorder.cpp +++ b/dGame/dCinema/Recorder.cpp @@ -28,7 +28,7 @@ void Recorder::AddRecord(Record* record) return; } - Game::logger->Log("Recorder", "Adding record"); + LOG("Adding record"); const auto currentTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); @@ -41,7 +41,7 @@ void Recorder::AddRecord(Record* record) } void Recorder::Act(Entity* actor, Play* variables) { - Game::logger->Log("Recorder", "Acting %d steps", m_Records.size()); + LOG("Acting %d steps", m_Records.size()); // Loop through all records ActingDispatch(actor, 0, variables); @@ -91,7 +91,7 @@ void Recorder::ActingDispatch(Entity* actor, size_t index, Play* variables) { } } - Game::logger->Log("Recorder", "Failed to find fork label success: %s", forkRecord->success.c_str()); + LOG("Failed to find fork label success: %s", forkRecord->success.c_str()); return; } @@ -106,7 +106,7 @@ void Recorder::ActingDispatch(Entity* actor, size_t index, Play* variables) { } } - Game::logger->Log("Recorder", "Failed to find fork label failure: %s", forkRecord->failure.c_str()); + LOG("Failed to find fork label failure: %s", forkRecord->failure.c_str()); return; } @@ -126,7 +126,7 @@ void Recorder::ActingDispatch(Entity* actor, size_t index, Play* variables) { } } - Game::logger->Log("Recorder", "Failed to find jump label: %s", jumpRecord->label.c_str()); + LOG("Failed to find jump label: %s", jumpRecord->label.c_str()); return; } @@ -631,6 +631,10 @@ Recorder* Recorder::LoadFromFile(const std::string& filename) { for (auto* element = root->FirstChildElement(); element; element = element->NextSiblingElement()) { const std::string name = element->Name(); + if (!element->Attribute("t")) { + element->SetAttribute("t", 0.0f); + } + if (name == "MovementRecord") { MovementRecord* record = new MovementRecord(); record->Deserialize(element); diff --git a/dGame/dCinema/Scene.cpp b/dGame/dCinema/Scene.cpp index 7465e4f5..a146530a 100644 --- a/dGame/dCinema/Scene.cpp +++ b/dGame/dCinema/Scene.cpp @@ -64,6 +64,8 @@ bool Cinema::Scene::IsPlayerInBounds(Entity* player) const { auto distance = NiPoint3::Distance(position, m_Center); + LOG("Player distance from scene: %f, with bounds %f", distance, m_Bounds); + // The player may be within 20% of the bounds return distance <= (m_Bounds * 1.2f); } @@ -132,7 +134,7 @@ Play* Cinema::Scene::Act(Entity* player) { ServerPreconditions::AddSoloActor(entity->GetObjectID(), player->GetObjectID()); } - Game::logger->Log("Scene", "Spawing object %d", entity->GetObjectID()); + LOG("Spawing object %d", entity->GetObjectID()); } for (const auto& [prefab, position] : m_Prefabs) { @@ -143,12 +145,14 @@ Play* Cinema::Scene::Act(Entity* player) { if (player != nullptr) { for (const auto& entity : entities) { ServerPreconditions::AddSoloActor(entity, player->GetObjectID()); - - play->entities.emplace(entity); } } + + for (const auto& entity : entities) { + play->entities.emplace(entity); + } - Game::logger->Log("Scene", "Spawing prefab %d", instanceId); + LOG("Spawing prefab %d", instanceId); } for (const auto& [npc, meta] : m_NPCs) { @@ -185,9 +189,9 @@ Play* Cinema::Scene::Act(Entity* player) { actor->SetVar(u"npcName", name); } - play->entities.emplace(entity->GetObjectID()); + play->entities.emplace(actor->GetObjectID()); - Game::logger->Log("Scene", "Spawing npc %d", entity->GetObjectID()); + LOG("Spawing npc %d", entity->GetObjectID()); } if (player != nullptr) { @@ -209,7 +213,7 @@ Scene& Cinema::Scene::LoadFromFile(std::string file) { tinyxml2::XMLElement* root = doc.FirstChildElement("Scene"); if (!root) { - Game::logger->Log("Scene", "Failed to load scene from file: %s", file.c_str()); + LOG("Failed to load scene from file: %s", file.c_str()); m_Scenes.emplace(file, scene); @@ -271,7 +275,7 @@ Scene& Cinema::Scene::LoadFromFile(std::string file) { scene.AddNPC(npc, name, Recording::Recorder::LoadFromFile(act)); } - Game::logger->Log("Scene", "Loaded scene from file: %s", file.c_str()); + LOG("Loaded scene from file: %s", file.c_str()); m_Scenes.emplace(file, scene); diff --git a/dGame/dCinema/media/isolation.png b/dGame/dCinema/media/isolation.png new file mode 100644 index 00000000..69cba1e4 Binary files /dev/null and b/dGame/dCinema/media/isolation.png differ diff --git a/dGame/dUtilities/VanityUtilities.cpp b/dGame/dUtilities/VanityUtilities.cpp index 4213b81c..084450e3 100644 --- a/dGame/dUtilities/VanityUtilities.cpp +++ b/dGame/dUtilities/VanityUtilities.cpp @@ -122,13 +122,13 @@ void VanityUtilities::SpawnVanity() { auto* scriptComponent = npcEntity->GetComponent(); - Game::logger->Log("VanityUtilities", "Script: %s", npc.m_Script.c_str()); + LOG_DEBUG("Script: %s", npc.m_Script.c_str()); if (scriptComponent && !npc.m_Script.empty()) { scriptComponent->SetScript(npc.m_Script); scriptComponent->SetSerialized(false); - Game::logger->Log("VanityUtilities", "Setting script to %s", npc.m_Script.c_str()); + LOG_DEBUG("Setting script to %s", npc.m_Script.c_str()); for (const auto& npc : npc.m_Flags) { npcEntity->SetVar(GeneralUtils::ASCIIToUTF16(npc.first), npc.second); @@ -168,7 +168,7 @@ Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoin if (entity->GetVar(u"noGhosting")) entity->SetIsGhostingCandidate(false); // Debug print - Game::logger->Log("VanityUtilities", "Spawning NPC %s (%i) at %f, %f, %f", name.c_str(), lot, position.x, position.y, position.z); + LOG_DEBUG("Spawning NPC %s (%i) at %f, %f, %f", name.c_str(), lot, position.x, position.y, position.z); auto* inventoryComponent = entity->GetComponent(); @@ -188,10 +188,10 @@ Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoin if (scriptComponent == nullptr) { - entity->AddComponent(eReplicaComponentType::SCRIPT, new ScriptComponent(entity, "", false)); + entity->AddComponent("", false); } - Game::logger->Log("VanityUtilities", "NPC has script component? %s", (entity->GetComponent() != nullptr) ? "true" : "false"); + LOG_DEBUG("NPC has script component? %s", (entity->GetComponent() != nullptr) ? "true" : "false"); Game::entityManager->ConstructEntity(entity);