From 685bd5d45bad5b65f02e7b66ce9f2865a03a8d3a Mon Sep 17 00:00:00 2001 From: wincent Date: Sat, 17 Feb 2024 23:07:16 +0100 Subject: [PATCH] Updated to new API --- dGame/Entity.cpp | 4 +- dGame/EntityManager.cpp | 4 +- dGame/dCinema/Recorder.cpp | 6 +- dGame/dCinema/Recorder.h | 1 - dGame/dUtilities/SlashCommandHandler.cpp | 104 ++++++++++++++++------- 5 files changed, 76 insertions(+), 43 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 3488aad2..a6e01656 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -2175,8 +2175,8 @@ void Entity::ProcessPositionUpdate(PositionUpdate& update) { update.velocity, update.angularVelocity, update.onGround, - update.velocity != NiPoint3::ZERO, - update.angularVelocity != NiPoint3::ZERO + update.velocity != NiPoint3Constant::ZERO, + update.angularVelocity != NiPoint3Constant::ZERO )); } } diff --git a/dGame/EntityManager.cpp b/dGame/EntityManager.cpp index 694f9b44..718c3bcf 100644 --- a/dGame/EntityManager.cpp +++ b/dGame/EntityManager.cpp @@ -538,13 +538,13 @@ void EntityManager::CheckGhosting(Entity* entity) { const auto precondition = ServerPreconditions::CheckPreconditions(entity, player); - if (observed && (distance > ghostingDistanceMax || !precondition)) { + if (observed && (distance > m_GhostDistanceMaxSquared || !precondition)) { ghostComponent->GhostEntity(id); DestructEntity(entity, player->GetSystemAddress()); entity->SetObservers(entity->GetObservers() - 1); - } else if (!observed && (ghostingDistanceMin > distance && precondition)) { + } else if (!observed && (m_GhostDistanceMinSqaured > distance && precondition)) { ghostComponent->ObserveEntity(id); ConstructEntity(entity, player->GetSystemAddress()); diff --git a/dGame/dCinema/Recorder.cpp b/dGame/dCinema/Recorder.cpp index 1b304209..7e69e933 100644 --- a/dGame/dCinema/Recorder.cpp +++ b/dGame/dCinema/Recorder.cpp @@ -1081,11 +1081,7 @@ Cinema::Recording::PlayEffectRecord::PlayEffectRecord(const std::string& effect) } void Cinema::Recording::PlayEffectRecord::Act(Entity* actor) { - int32_t effectID = 0; - - if (!GeneralUtils::TryParse(effect, effectID)) { - return; - } + int32_t effectID = GeneralUtils::TryParse(effect).value_or(0); GameMessages::SendPlayFXEffect( actor->GetObjectID(), diff --git a/dGame/dCinema/Recorder.h b/dGame/dCinema/Recorder.h index 02d7e480..3453d88d 100644 --- a/dGame/dCinema/Recorder.h +++ b/dGame/dCinema/Recorder.h @@ -1,6 +1,5 @@ #pragma once -#include "Player.h" #include "Game.h" #include "EntityManager.h" #include "tinyxml2.h" diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 3c947226..e357bdce 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -716,9 +716,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "removemission" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) { if (args.size() == 0) return; - uint32_t missionID; + uint32_t missionID = GeneralUtils::TryParse(args.at(0)).value_or(0); - if (!GeneralUtils::TryParse(args[0], missionID)) { + if (missionID == 0) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid mission id."); return; } @@ -914,9 +914,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit // If there is an argument, set the lot if (args.size() > 0) { - if (!GeneralUtils::TryParse(args[0], info.lot)) { - ChatPackets::SendSystemMessage(sysAddr, u"Invalid lot."); - return; + const auto lotOptional = GeneralUtils::TryParse(args[0]); + if (lotOptional) { + info.lot = lotOptional.value(); } } @@ -998,9 +998,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit float scale = 1.0f; if (args.size() >= 2) { - if (!GeneralUtils::TryParse(args[1], scale)) { - ChatPackets::SendSystemMessage(sysAddr, u"Invalid scale."); - return; + const auto scaleOptional = GeneralUtils::TryParse(args[1]); + if (scaleOptional) { + scale = scaleOptional.value(); } } @@ -1012,9 +1012,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } if (chatCommand == "prefab-destroy" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER && args.size() == 1) { - size_t id; + size_t id = GeneralUtils::TryParse(args[0]).value_or(0); - if (!GeneralUtils::TryParse(args[0], id)) { + if (id == 0) { ChatPackets::SendSystemMessage(sysAddr, u"Invalid prefab ID."); return; } @@ -2240,16 +2240,28 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } } } else if (args[1] == "-rotate" && args.size() >= 4) { - const auto& rx = args[2]; - const auto& ry = args[3]; - const auto& rz = args[4]; - - float x, y, z; - - if (!GeneralUtils::TryParse(rx, x) || !GeneralUtils::TryParse(ry, y) || !GeneralUtils::TryParse(rz, z)) { + const auto rx = GeneralUtils::TryParse(args.at(2)); + if (!rx) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid x."); return; } + const auto ry = GeneralUtils::TryParse(args.at(3)); + if (!ry) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid y."); + return; + } + + const auto rz = GeneralUtils::TryParse(args.at(4)); + if (!rz) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid z."); + return; + } + + float x = rx.value(); + float y = ry.value(); + float z = rz.value(); + // Degrees to radia x *= 0.0174533f; y *= 0.0174533f; @@ -2261,41 +2273,67 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit Game::entityManager->SerializeEntity(closest); } else if (args[1] == "-translate" && args.size() >= 4) { - const auto& tx = args[2]; - const auto& ty = args[3]; - const auto& tz = args[4]; - - float x, y, z; - - if (!GeneralUtils::TryParse(tx, x) || !GeneralUtils::TryParse(ty, y) || !GeneralUtils::TryParse(tz, z)) { + const auto rx = GeneralUtils::TryParse(args.at(2)); + if (!rx) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid x."); return; } + const auto ry = GeneralUtils::TryParse(args.at(3)); + if (!ry) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid y."); + return; + } + + const auto rz = GeneralUtils::TryParse(args.at(4)); + if (!rz) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid z."); + return; + } + + float x = rx.value(); + float y = ry.value(); + float z = rz.value(); + const auto translation = NiPoint3(x, y, z); closest->SetPosition(closest->GetPosition() + translation); Game::entityManager->SerializeEntity(closest); } else if (args[1] == "-warp" && args.size() >= 4) { - const auto& tx = args[2]; - const auto& ty = args[3]; - const auto& tz = args[4]; - - float x, y, z; - - if (!GeneralUtils::TryParse(tx, x) || !GeneralUtils::TryParse(ty, y) || !GeneralUtils::TryParse(tz, z)) { + const auto rx = GeneralUtils::TryParse(args.at(2)); + if (!rx) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid x."); return; } + const auto ry = GeneralUtils::TryParse(args.at(3)); + if (!ry) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid y."); + return; + } + + const auto rz = GeneralUtils::TryParse(args.at(4)); + if (!rz) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid z."); + return; + } + + float x = rx.value(); + float y = ry.value(); + float z = rz.value(); + + const auto translation = NiPoint3(x, y, z); closest->SetPosition(translation); Game::entityManager->SerializeEntity(closest); } else if (args[1] == "-fx" && args.size() >= 4) { - int32_t effectID = 0; + int32_t effectID = GeneralUtils::TryParse(args[2]).value_or(-1); - if (!GeneralUtils::TryParse(args[2], effectID)) { + if (effectID == -1) { + ChatPackets::SendSystemMessage(sysAddr, u"Invalid effect ID."); return; }