diff --git a/CMakeVariables.txt b/CMakeVariables.txt index d9430d9d..6d149b69 100644 --- a/CMakeVariables.txt +++ b/CMakeVariables.txt @@ -19,7 +19,7 @@ INCLUDE_BACKTRACE=0 COMPILE_BACKTRACE=0 # Set to the number of jobs (make -j equivalent) to compile the mariadbconn files with. -MARIADB_CONNECTOR_COMPILE_JOBS=1 +MARIADB_CONNECTOR_COMPILE_JOBS= # When set to 1 and uncommented, compiling and linking testing folders and libraries will be done. ENABLE_TESTING=1 diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 7c137a62..f7540ed5 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -2125,9 +2125,7 @@ void Entity::ProcessPositionUpdate(PositionUpdate& update) { possessedControllablePhysicsComponent->SetIsOnGround(update.onGround); possessedControllablePhysicsComponent->SetIsOnRail(update.onRail); possessedControllablePhysicsComponent->SetVelocity(update.velocity); - possessedControllablePhysicsComponent->SetDirtyVelocity(update.velocity != NiPoint3Constant::ZERO); possessedControllablePhysicsComponent->SetAngularVelocity(update.angularVelocity); - possessedControllablePhysicsComponent->SetDirtyAngularVelocity(update.angularVelocity != NiPoint3Constant::ZERO); } Game::entityManager->SerializeEntity(possassableEntity); } @@ -2149,9 +2147,7 @@ void Entity::ProcessPositionUpdate(PositionUpdate& update) { controllablePhysicsComponent->SetIsOnGround(update.onGround); controllablePhysicsComponent->SetIsOnRail(update.onRail); controllablePhysicsComponent->SetVelocity(update.velocity); - controllablePhysicsComponent->SetDirtyVelocity(update.velocity != NiPoint3Constant::ZERO); controllablePhysicsComponent->SetAngularVelocity(update.angularVelocity); - controllablePhysicsComponent->SetDirtyAngularVelocity(update.angularVelocity != NiPoint3Constant::ZERO); auto* ghostComponent = GetComponent(); if (ghostComponent) ghostComponent->SetGhostReferencePoint(update.position); diff --git a/dGame/dComponents/ControllablePhysicsComponent.cpp b/dGame/dComponents/ControllablePhysicsComponent.cpp index 38a2478b..33f8ae81 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.cpp +++ b/dGame/dComponents/ControllablePhysicsComponent.cpp @@ -22,7 +22,6 @@ ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity) : Phy m_IsOnGround = true; m_IsOnRail = false; m_DirtyVelocity = true; - m_DirtyAngularVelocity = true; m_dpEntity = nullptr; m_Static = false; m_SpeedMultiplier = 1; @@ -68,7 +67,7 @@ ControllablePhysicsComponent::~ControllablePhysicsComponent() { } void ControllablePhysicsComponent::Update(float deltaTime) { - if (m_Velocity == NiPoint3::ZERO) return; + if (m_Velocity == NiPoint3Constant::ZERO) return; SetPosition(m_Position + (m_Velocity * deltaTime)); Game::entityManager->SerializeEntity(m_Parent); } @@ -117,8 +116,8 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo if (!bIsInitialUpdate) m_DirtyBubble = false; } - bool isVelocityZero = m_Velocity != NiPoint3::ZERO; - bool isAngularVelocityZero = m_AngularVelocity != NiPoint3::ZERO; + bool isVelocityZero = m_Velocity != NiPoint3Constant::ZERO; + bool isAngularVelocityZero = m_AngularVelocity != NiPoint3Constant::ZERO; bool shouldWriteFrameStats = m_DirtyPosition || bIsInitialUpdate || isVelocityZero || isAngularVelocityZero; outBitStream->Write(m_DirtyPosition || bIsInitialUpdate); if (m_DirtyPosition || bIsInitialUpdate) { diff --git a/dGame/dComponents/HavokVehiclePhysicsComponent.cpp b/dGame/dComponents/HavokVehiclePhysicsComponent.cpp index 9c22ff47..bc80c9ec 100644 --- a/dGame/dComponents/HavokVehiclePhysicsComponent.cpp +++ b/dGame/dComponents/HavokVehiclePhysicsComponent.cpp @@ -67,7 +67,7 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo outBitStream->Write(m_IsOnGround); outBitStream->Write(m_IsOnRail); - bool isVelocityZero = m_Velocity == NiPoint3::ZERO; + bool isVelocityZero = m_Velocity == NiPoint3Constant::ZERO; outBitStream->Write(isVelocityZero); if (isVelocityZero) { @@ -76,7 +76,7 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo outBitStream->Write(m_Velocity.z); } - bool isAngularVelocityZero = m_AngularVelocity == NiPoint3::ZERO; + bool isAngularVelocityZero = m_AngularVelocity == NiPoint3Constant::ZERO; outBitStream->Write(isAngularVelocityZero); if (isAngularVelocityZero) { outBitStream->Write(m_AngularVelocity.x); diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index 31676094..711bc0af 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -73,30 +73,30 @@ float MovementAIComponent::GetCurrentPathWaypointSpeed() const { void MovementAIComponent::SetupPath(const std::string& pathname) { std::string path = pathname; - if (path.empty()) path = m_Parent->GetVarAsString(u"attached_path"); if (path.empty()) { - Game::logger->Log("MovementAIComponent", "No path to load for %i:%llu", m_Parent->GetLOT(), m_Parent->GetObjectID()); - return; + path = m_Parent->GetVarAsString(u"attached_path"); + if (path.empty()) { + LOG("No path to load for %i:%llu", m_Parent->GetLOT(), m_Parent->GetObjectID()); + return; + } } const Path* pathData = Game::zoneManager->GetZone()->GetPath(path); if (pathData) { - Game::logger->Log("MovementAIComponent", "found path %i %s", m_Parent->GetLOT(), path.c_str()); + LOG("found path %i %s", m_Parent->GetLOT(), path.c_str()); m_Path = pathData; if (!HasAttachedPathStart() && m_Parent->HasVar(u"attached_path_start")) m_StartingWaypointIndex = m_Parent->GetVar(u"attached_path_start"); if (m_Path && HasAttachedPathStart() && (m_StartingWaypointIndex < 0 || m_StartingWaypointIndex >= m_Path->pathWaypoints.size())) { - Game::logger->Log( - "MovementAIComponent", - "WARNING: attached path start is out of bounds for %i:%llu, defaulting path start to 0", + LOG("WARNING: attached path start is out of bounds for %i:%llu, defaulting path start to 0", m_Parent->GetLOT(), m_Parent->GetObjectID()); m_StartingWaypointIndex = 0; } std::vector waypoints; - for (auto& waypoint : m_Path->pathWaypoints) { + for (const auto& waypoint : m_Path->pathWaypoints) { waypoints.push_back(waypoint.position); } SetPath(waypoints); } else { - Game::logger->Log("MovementAIComponent", "No path found for %i:%llu", m_Parent->GetLOT(), m_Parent->GetObjectID()); + LOG("No path found for %i:%llu", m_Parent->GetLOT(), m_Parent->GetObjectID()); } } @@ -270,7 +270,7 @@ bool MovementAIComponent::Warp(const NiPoint3& point) { void MovementAIComponent::Pause() { if (AtFinalWaypoint() || IsPaused()) return; SetPosition(ApproximateLocation()); - SetVelocity(NiPoint3::ZERO); + SetVelocity(NiPoint3Constant::ZERO); // Clear this as we may be somewhere else when we resume movement. m_InterpolatedWaypoints.clear(); @@ -325,7 +325,7 @@ const NiPoint3& MovementAIComponent::GetCurrentPathWaypoint() const { return m_CurrentPath.at(m_CurrentPathWaypointIndex); } -void MovementAIComponent::SetPath(std::vector path, bool startInReverse) { +void MovementAIComponent::SetPath(const std::vector& path, bool startInReverse) { if (path.empty()) return; m_CurrentPath = path; m_IsInReverse = startInReverse; @@ -549,11 +549,11 @@ void MovementAIComponent::HandleWaypointArrived(uint32_t commandIndex) { GameMessages::SendPlayNDAudioEmitter(m_Parent, UNASSIGNED_SYSTEM_ADDRESS, data); break; case eWaypointCommandType::BOUNCE: - Game::logger->LogDebug("MovementAIComponent", "Unable to process bounce waypoint command server side!"); + LOG("Unable to process bounce waypoint command server side!"); break; case eWaypointCommandType::INVALID: default: - Game::logger->LogDebug("MovementAIComponent", "Got invalid waypoint command %i", command); + LOG("Got invalid waypoint command %i", command); break; } @@ -583,20 +583,18 @@ void MovementAIComponent::HandleWaypointCommandCastSkill(const std::string& data if (data.empty()) return; auto* skillComponent = m_Parent->GetComponent(); if (!skillComponent) { - Game::logger->LogDebug("MovementAIComponent::HandleWaypointCommandCastSkill", "Skill component not found!"); + LOG("Skill component not found!"); return; } - uint32_t skillId = 0; - if (!GeneralUtils::TryParse(data, skillId)) return; - if (skillId != 0) skillComponent->CastSkill(skillId); - return; + auto skillId = GeneralUtils::TryParse(data); + if (skillId && skillId != 0) skillComponent->CastSkill(skillId.value()); } void MovementAIComponent::HandleWaypointCommandEquipInventory(const std::string& data) { if (data.empty()) return; auto* inventoryComponent = m_Parent->GetComponent(); if (!inventoryComponent) { - Game::logger->LogDebug("MovementAIComponent::HandleWaypointCommandEquipInventory", "Inventory component not found!"); + LOG("Inventory component not found!"); return; } // the client says use slot 0 of items @@ -611,7 +609,7 @@ void MovementAIComponent::HandleWaypointCommandUnequipInventory(const std::strin if (data.empty()) return; auto* inventoryComponent = m_Parent->GetComponent(); if (!inventoryComponent) { - Game::logger->LogDebug("MovementAIComponent::HandleWaypointCommandEquipInventory", "Inventory component not found!"); + LOG("Inventory component not found!"); return; } // the client says use slot 0 of items @@ -623,35 +621,50 @@ void MovementAIComponent::HandleWaypointCommandUnequipInventory(const std::strin } float MovementAIComponent::HandleWaypointCommandDelay(const std::string& data) { - float delay = 0.0f; - std::string delayString = data; - if (!GeneralUtils::TryParse(delayString, delay)) { - Game::logger->LogDebug("MovementAIComponentAronwk", "Failed to parse delay %s", data.c_str()); + auto delay = GeneralUtils::TryParse(data); + if (!delay) { + LOG("Failed to parse delay %s", data.c_str()); } - return delay; + return delay.value_or(0.0f); } void MovementAIComponent::HandleWaypointCommandTeleport(const std::string& data) { auto posString = GeneralUtils::SplitString(data, ','); if (posString.size() == 0) return; auto newPos = NiPoint3(); - if (posString.size() == 1 && !GeneralUtils::TryParse(posString.at(0), newPos.x)) return; - if (posString.size() == 2 && !GeneralUtils::TryParse(posString.at(1), newPos.y)) return; - if (posString.size() == 3 && !GeneralUtils::TryParse(posString.at(2), newPos.z)) return; - GameMessages::SendTeleport(m_Parent->GetObjectID(), newPos, NiQuaternion::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS); + std::optional intermediate; + if (posString.size() >= 1) { + intermediate = GeneralUtils::TryParse(posString.at(0)); + if (!intermediate) return; + + newPos.x = intermediate.value(); + if (posString.size() >= 2) { + intermediate = GeneralUtils::TryParse(posString.at(1)); + if (!intermediate) return; + + newPos.y = intermediate.value(); + if (posString.size() >= 3) { + intermediate = GeneralUtils::TryParse(posString.at(2)); + if (!intermediate) return; + + newPos.z = intermediate.value(); + } + } + } + GameMessages::SendTeleport(m_Parent->GetObjectID(), newPos, NiQuaternionConstant::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS); } void MovementAIComponent::HandleWaypointCommandPathSpeed(const std::string& data) { - float speed = 0.0; - if (!GeneralUtils::TryParse(data, speed)) return; - SetMaxSpeed(speed); + auto speed = GeneralUtils::TryParse(data); + if (!speed) return; + SetMaxSpeed(speed.value()); } void MovementAIComponent::HandleWaypointCommandRemoveNPC(const std::string& data) { if (data.empty()) return; auto* proximityMonitorComponent = m_Parent->GetComponent(); if (!proximityMonitorComponent) { - Game::logger->LogDebug("MovementAIComponent::HandleWaypointCommandRemoveNPC", "Proximity monitor component not found!"); + LOG("Proximity monitor component not found!"); return; } const auto foundObjs = proximityMonitorComponent->GetProximityObjects("KillOBJS"); @@ -660,11 +673,13 @@ void MovementAIComponent::HandleWaypointCommandRemoveNPC(const std::string& data if (!entity) return; auto* destroyableComponent = m_Parent->GetComponent(); if (!destroyableComponent) { - Game::logger->LogDebug("MovementAIComponent::HandleWaypointCommandRemoveNPC", "Destroyable component not found!"); + LOG("Destroyable component not found!"); return; } - uint32_t factionID = -1; - if (!GeneralUtils::TryParse(data, factionID)) return; + int32_t factionID = -1; + auto parsed = GeneralUtils::TryParse(data); + if (!parsed) return; + factionID = parsed.value(); if (destroyableComponent->BelongsToFaction(factionID)) m_Parent->Kill(); } } @@ -676,7 +691,9 @@ void MovementAIComponent::HandleWaypointCommandChangeWaypoint(const std::string& if (data.find(",") != std::string::npos) { auto datas = GeneralUtils::SplitString(data, ','); path_string = datas.at(0); - if (!GeneralUtils::TryParse(datas.at(1), index)) return; + auto parsed = GeneralUtils::TryParse(datas.at(1)); + if (!parsed) return; + index = parsed.value(); } else path_string = data; if (path_string != "") { @@ -687,7 +704,9 @@ void MovementAIComponent::HandleWaypointCommandChangeWaypoint(const std::string& void MovementAIComponent::HandleWaypointCommandSpawnObject(const std::string& data) { LOT newObjectLOT = 0; - if (!GeneralUtils::TryParse(data, newObjectLOT)) return; + auto parsed = GeneralUtils::TryParse(data); + if (!parsed) return; + newObjectLOT = parsed.value(); EntityInfo info{}; info.lot = newObjectLOT; info.pos = m_Parent->GetPosition(); diff --git a/dGame/dComponents/MovementAIComponent.h b/dGame/dComponents/MovementAIComponent.h index e2245ca8..2f1dcebf 100644 --- a/dGame/dComponents/MovementAIComponent.h +++ b/dGame/dComponents/MovementAIComponent.h @@ -224,7 +224,7 @@ public: * Sets a path to follow for the AI * @param path the path to follow */ - void SetPath(std::vector path, bool startsInReverse = false); + void SetPath(const std::vector& path, bool startsInReverse = false); // Advance the path waypoint index and return if there is a next waypoint bool AdvancePathWaypointIndex(); diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index 9b4fad79..366bebd3 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -162,7 +162,7 @@ void MovingPlatformComponent::StartPathing() { const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex]; subComponent->mPosition = currentWaypoint.position; - subComponent->mSpeed = currentWaypoint.speed; + subComponent->mSpeed = currentWaypoint.movingPlatform.speed; subComponent->mWaitTime = currentWaypoint.movingPlatform.wait; targetPosition = nextWaypoint.position; @@ -213,7 +213,7 @@ void MovingPlatformComponent::ContinuePathing() { const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex]; subComponent->mPosition = currentWaypoint.position; - subComponent->mSpeed = currentWaypoint.speed; + subComponent->mSpeed = currentWaypoint.movingPlatform.speed; subComponent->mWaitTime = currentWaypoint.movingPlatform.wait; // + 2; pathSize = m_Path->pathWaypoints.size() - 1; diff --git a/dGame/dComponents/ProximityMonitorComponent.cpp b/dGame/dComponents/ProximityMonitorComponent.cpp index fdca78aa..2bc68d5c 100644 --- a/dGame/dComponents/ProximityMonitorComponent.cpp +++ b/dGame/dComponents/ProximityMonitorComponent.cpp @@ -61,17 +61,17 @@ bool ProximityMonitorComponent::IsInProximity(const std::string& name, LWOOBJID } void ProximityMonitorComponent::Update(float deltaTime) { - for (const auto& [name, dpentity] : m_ProximitiesData) { - if (!dpentity) continue; - dpentity->SetPosition(m_Parent->GetPosition()); + for (const auto& prox : m_ProximitiesData) { + if (!prox.second) continue; + prox.second->SetPosition(m_Parent->GetPosition()); //Process enter events - for (auto* en : dpentity->GetNewObjects()) { - m_Parent->OnCollisionProximity(en->GetObjectID(), name, "ENTER"); + for (auto* en : prox.second->GetNewObjects()) { + m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "ENTER"); } //Process exit events - for (auto* en : dpentity->GetRemovedObjects()) { - m_Parent->OnCollisionProximity(en->GetObjectID(), name, "LEAVE"); + for (auto* en : prox.second->GetRemovedObjects()) { + m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "LEAVE"); } } } diff --git a/dGame/dComponents/TriggerComponent.cpp b/dGame/dComponents/TriggerComponent.cpp index 9148abfe..d5933e50 100644 --- a/dGame/dComponents/TriggerComponent.cpp +++ b/dGame/dComponents/TriggerComponent.cpp @@ -227,9 +227,9 @@ void TriggerComponent::HandleSetPath(Entity* targetEntity, std::vectorSetupPath(argArray.at(0)); if (argArray.size() >= 2) { - int32_t index = 0; - if (!GeneralUtils::TryParse(argArray.at(1), index)) return; - movementAIComponent->SetPathStartingWaypointIndex(index); + auto index = GeneralUtils::TryParse(argArray.at(1)); + if (!index) return; + movementAIComponent->SetPathStartingWaypointIndex(index.value()); } if (argArray.size() >= 3 && argArray.at(2) == "1") movementAIComponent->ReversePath(); } diff --git a/dScripts/02_server/Map/AM/CMakeLists.txt b/dScripts/02_server/Map/AM/CMakeLists.txt index 7d9e7db9..4212612f 100644 --- a/dScripts/02_server/Map/AM/CMakeLists.txt +++ b/dScripts/02_server/Map/AM/CMakeLists.txt @@ -17,7 +17,7 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_AM "AmBlueX.cpp" "AmTeapotServer.cpp" "WanderingVendor.cpp" - PARENT_SCOPE) +) add_library(dScriptsServerMapAM ${DSCRIPTS_SOURCES_02_SERVER_MAP_AM}) target_include_directories(dScriptsServerMapAM PUBLIC ".") diff --git a/dScripts/02_server/Map/AM/WanderingVendor.cpp b/dScripts/02_server/Map/AM/WanderingVendor.cpp index 996eeec5..ced5ca64 100644 --- a/dScripts/02_server/Map/AM/WanderingVendor.cpp +++ b/dScripts/02_server/Map/AM/WanderingVendor.cpp @@ -18,7 +18,7 @@ void WanderingVendor::OnProximityUpdate(Entity* self, Entity* entering, std::str } else if (status == "LEAVE") { auto* proximityMonitorComponent = self->GetComponent(); if (!proximityMonitorComponent) { - Game::logger->LogDebug("MovementAIComponent::HandleWaypointCommandRemoveNPC", "Proximity monitor component not found!"); + LOG("Proximity monitor component not found!"); return; } const auto proxObjs = proximityMonitorComponent->GetProximityObjects("playermonitor"); diff --git a/dScripts/zone/CMakeLists.txt b/dScripts/zone/CMakeLists.txt index 93ea70ca..cfd1f83d 100644 --- a/dScripts/zone/CMakeLists.txt +++ b/dScripts/zone/CMakeLists.txt @@ -22,6 +22,7 @@ add_library(dScriptsZone STATIC ${DSCRIPTS_SOURCES_ZONE}) target_include_directories(dScriptsZone PUBLIC "." "AG" "LUPs" + "LUPs/RobotCity_Intro" "PROPERTY" "PROPERTY/FV" "PROPERTY/GF" diff --git a/dZoneManager/Zone.cpp b/dZoneManager/Zone.cpp index 8fac7c37..fef8eca6 100644 --- a/dZoneManager/Zone.cpp +++ b/dZoneManager/Zone.cpp @@ -420,7 +420,7 @@ void Zone::LoadPath(std::istream& file) { if (path.pathType == PathType::MovingPlatform) { BinaryIO::BinaryRead(file, waypoint.movingPlatform.lockPlayer); - BinaryIO::BinaryRead(file, waypoint.speed); + BinaryIO::BinaryRead(file, waypoint.movingPlatform.speed); BinaryIO::BinaryRead(file, waypoint.movingPlatform.wait); if (path.pathVersion >= 13) { BinaryIO::ReadString(file, waypoint.movingPlatform.departSound, BinaryIO::ReadType::WideString); @@ -439,7 +439,7 @@ void Zone::LoadPath(std::istream& file) { BinaryIO::BinaryRead(file, waypoint.racing.planeHeight); BinaryIO::BinaryRead(file, waypoint.racing.shortestDistanceToEnd); } else if (path.pathType == PathType::Rail) { - if (path.pathVersion > 16) BinaryIO::BinaryRead(file, waypoint.speed); + if (path.pathVersion > 16) BinaryIO::BinaryRead(file, waypoint.rail.speed); } // object LDF configs @@ -460,7 +460,7 @@ void Zone::LoadPath(std::istream& file) { auto waypointCommand = WaypointCommandType::StringToWaypointCommandType(parameter); if (waypointCommand == eWaypointCommandType::DELAY) value.erase(std::remove_if(value.begin(), value.end(), ::isspace), value.end()); if (waypointCommand != eWaypointCommandType::INVALID) waypoint.commands.push_back(WaypointCommand(waypointCommand, value)); - else Game::logger->Log("Zone", "Tried to load invalid waypoint command '%s'", parameter.c_str()); + else LOG("Tried to load invalid waypoint command '%s'", parameter.c_str()); } else { ldfConfig = LDFBaseData::DataFromString(parameter + "=" + value); if (ldfConfig) waypoint.config.push_back(ldfConfig); diff --git a/dZoneManager/Zone.h b/dZoneManager/Zone.h index 2deca3d1..30e4682f 100644 --- a/dZoneManager/Zone.h +++ b/dZoneManager/Zone.h @@ -50,6 +50,7 @@ struct SceneTransition { struct MovingPlatformPathWaypoint { uint8_t lockPlayer; + float speed; float wait; std::string departSound; std::string arriveSound; @@ -71,13 +72,17 @@ struct RacingPathWaypoint { float shortestDistanceToEnd; }; +struct RailPathWaypoint { + float speed; +}; + struct PathWaypoint { NiPoint3 position; NiQuaternion rotation; // not included in all, but it's more convenient here MovingPlatformPathWaypoint movingPlatform; CameraPathWaypoint camera; RacingPathWaypoint racing; - float speed = 1.0f; + RailPathWaypoint rail; std::vector config; std::vector commands; };