breakout object bits into scoped enum (#997)

* breakout object bits into enum class
tested that things still work as expected
use the inplace set bits where appropiate

* add inline
This commit is contained in:
Aaron Kimbrell
2023-04-25 13:17:40 -05:00
committed by GitHub
parent de1ddd3125
commit 4976701f37
17 changed files with 80 additions and 62 deletions

View File

@@ -18,6 +18,7 @@
#include "InventoryComponent.h"
#include "eMissionTaskType.h"
#include "eMissionState.h"
#include "eObjectBits.h"
#include "eGameMasterLevel.h"
Character::Character(uint32_t id, User* parentUser) {
@@ -69,8 +70,8 @@ Character::Character(uint32_t id, User* parentUser) {
//Set our objectID:
m_ObjectID = m_ID;
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_CHARACTER);
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(m_ObjectID, eObjectBits::CHARACTER);
GeneralUtils::SetBit(m_ObjectID, eObjectBits::PERSISTENT);
m_ParentUser = parentUser;
m_OurEntity = nullptr;
@@ -128,8 +129,8 @@ void Character::UpdateFromDatabase() {
//Set our objectID:
m_ObjectID = m_ID;
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_CHARACTER);
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(m_ObjectID, eObjectBits::CHARACTER);
GeneralUtils::SetBit(m_ObjectID, eObjectBits::PERSISTENT);
m_OurEntity = nullptr;
m_BuildMode = false;

View File

@@ -24,6 +24,7 @@
#include "Loot.h"
#include "eMissionTaskType.h"
#include "eTriggerEventType.h"
#include "eObjectBits.h"
//Component includes:
#include "Component.h"
@@ -952,9 +953,9 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke
if (m_ParentEntity != nullptr || m_SpawnerID != 0) {
outBitStream->Write1();
if (m_ParentEntity != nullptr) outBitStream->Write(GeneralUtils::SetBit(m_ParentEntity->GetObjectID(), OBJECT_BIT_CLIENT));
if (m_ParentEntity != nullptr) outBitStream->Write(GeneralUtils::SetBit(m_ParentEntity->GetObjectID(), static_cast<uint32_t>(eObjectBits::CLIENT)));
else if (m_Spawner != nullptr && m_Spawner->m_Info.isNetwork) outBitStream->Write(m_SpawnerID);
else outBitStream->Write(GeneralUtils::SetBit(m_SpawnerID, OBJECT_BIT_CLIENT));
else outBitStream->Write(GeneralUtils::SetBit(m_SpawnerID, static_cast<uint32_t>(eObjectBits::CLIENT)));
} else outBitStream->Write0();
outBitStream->Write(m_HasSpawnerNodeID);

View File

@@ -20,6 +20,7 @@
#include "MessageIdentifiers.h"
#include "dConfig.h"
#include "eTriggerEventType.h"
#include "eObjectBits.h"
#include "eGameMasterLevel.h"
#include "eReplicaComponentType.h"
@@ -108,11 +109,11 @@ Entity* EntityManager::CreateEntity(EntityInfo info, User* user, Entity* parentE
if (!controller && info.lot != 14) {
// The client flags means the client should render the entity
id = GeneralUtils::SetBit(id, OBJECT_BIT_CLIENT);
GeneralUtils::SetBit(id, eObjectBits::CLIENT);
// Spawned entities require the spawned flag to render
if (info.spawnerID != 0) {
id = GeneralUtils::SetBit(id, OBJECT_BIT_SPAWNED);
GeneralUtils::SetBit(id, eObjectBits::SPAWNED);
}
}
}

View File

@@ -23,6 +23,7 @@
#include "AssetManager.h"
#include "CDClientDatabase.h"
#include "dMessageIdentifiers.h"
#include "eObjectBits.h"
#include "eGameMasterLevel.h"
UserManager* UserManager::m_Address = nullptr;
@@ -313,16 +314,16 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
std::stringstream xml2;
LWOOBJID lwoidforshirt = idforshirt;
lwoidforshirt = GeneralUtils::SetBit(lwoidforshirt, OBJECT_BIT_CHARACTER);
lwoidforshirt = GeneralUtils::SetBit(lwoidforshirt, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(lwoidforshirt, eObjectBits::CHARACTER);
GeneralUtils::SetBit(lwoidforshirt, eObjectBits::PERSISTENT);
xml2 << xmlSave1 << "<i l=\"" << shirtLOT << "\" id=\"" << lwoidforshirt << "\" s=\"0\" c=\"1\" eq=\"1\" b=\"1\"/>";
std::string xmlSave2 = xml2.str();
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t idforpants) {
LWOOBJID lwoidforpants = idforpants;
lwoidforpants = GeneralUtils::SetBit(lwoidforpants, OBJECT_BIT_CHARACTER);
lwoidforpants = GeneralUtils::SetBit(lwoidforpants, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(lwoidforpants, eObjectBits::CHARACTER);
GeneralUtils::SetBit(lwoidforpants, eObjectBits::PERSISTENT);
std::stringstream xml3;
xml3 << xmlSave2 << "<i l=\"" << pantsLOT << "\" id=\"" << lwoidforpants << "\" s=\"1\" c=\"1\" eq=\"1\" b=\"1\"/>";
@@ -480,8 +481,8 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
}
LWOOBJID objectID = PacketUtils::ReadPacketS64(8, packet);
objectID = GeneralUtils::ClearBit(objectID, OBJECT_BIT_CHARACTER);
objectID = GeneralUtils::ClearBit(objectID, OBJECT_BIT_PERSISTENT);
GeneralUtils::ClearBit(objectID, eObjectBits::CHARACTER);
GeneralUtils::ClearBit(objectID, eObjectBits::PERSISTENT);
uint32_t charID = static_cast<uint32_t>(objectID);
Game::logger->Log("UserManager", "Received char rename request for ID: %llu (%u)", objectID, charID);

View File

@@ -6,6 +6,7 @@
#include "dLogger.h"
#include "SkillComponent.h"
#include "../dWorldServer/ObjectIDManager.h"
#include "eObjectBits.h"
void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
LWOOBJID target{};
@@ -107,7 +108,7 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt
for (auto i = 0u; i < this->m_projectileCount; ++i) {
auto id = static_cast<LWOOBJID>(ObjectIDManager::Instance()->GenerateObjectID());
id = GeneralUtils::SetBit(id, OBJECT_BIT_SPAWNED);
GeneralUtils::SetBit(id, eObjectBits::SPAWNED);
bitStream->Write(id);

View File

@@ -22,6 +22,7 @@
#include "Database.h"
#include "EntityInfo.h"
#include "eMissionTaskType.h"
#include "eObjectBits.h"
#include "eGameMasterLevel.h"
std::unordered_map<LOT, PetComponent::PetPuzzleData> PetComponent::buildCache{};
@@ -551,8 +552,8 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
LWOOBJID petSubKey = ObjectIDManager::Instance()->GenerateRandomObjectID();
petSubKey = GeneralUtils::SetBit(petSubKey, OBJECT_BIT_CHARACTER);
petSubKey = GeneralUtils::SetBit(petSubKey, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(petSubKey, eObjectBits::CHARACTER);
GeneralUtils::SetBit(petSubKey, eObjectBits::PERSISTENT);
m_DatabaseId = petSubKey;

View File

@@ -12,6 +12,7 @@
#include "UserManager.h"
#include "dLogger.h"
#include "AMFFormat.h"
#include "eObjectBits.h"
#include "eGameMasterLevel.h"
PropertyEntranceComponent::PropertyEntranceComponent(uint32_t componentID, Entity* parent) : Component(parent) {
@@ -243,8 +244,8 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
// Convert owner char id to LWOOBJID
LWOOBJID ownerObjId = owner;
ownerObjId = GeneralUtils::SetBit(ownerObjId, OBJECT_BIT_CHARACTER);
ownerObjId = GeneralUtils::SetBit(ownerObjId, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(ownerObjId, eObjectBits::CHARACTER);
GeneralUtils::SetBit(ownerObjId, eObjectBits::PERSISTENT);
// Query to get friend and best friend fields
auto friendCheck = Database::CreatePreppedStmt("SELECT best_friend FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?)");

View File

@@ -19,6 +19,7 @@
#include "PropertyEntranceComponent.h"
#include "InventoryComponent.h"
#include "eMissionTaskType.h"
#include "eObjectBits.h"
#include <vector>
#include "CppScripts.h"
@@ -66,8 +67,8 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent) : Compo
if (propertyEntry->next()) {
this->propertyId = propertyEntry->getUInt64(1);
this->owner = propertyEntry->getUInt64(2);
this->owner = GeneralUtils::SetBit(this->owner, OBJECT_BIT_CHARACTER);
this->owner = GeneralUtils::SetBit(this->owner, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(this->owner, eObjectBits::CHARACTER);
GeneralUtils::SetBit(this->owner, eObjectBits::PERSISTENT);
this->clone_Id = propertyEntry->getInt(2);
this->propertyName = propertyEntry->getString(5).c_str();
this->propertyDescription = propertyEntry->getString(6).c_str();
@@ -372,16 +373,15 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
info.emulated = true;
info.emulator = EntityManager::Instance()->GetZoneControlEntity()->GetObjectID();
LWOOBJID id = static_cast<LWOOBJID>(persistentId) | 1ull << OBJECT_BIT_CLIENT;
info.spawnerID = id;
info.spawnerID = persistentId;
GeneralUtils::SetBit(info.spawnerID, eObjectBits::CLIENT);
const auto spawnerId = dZoneManager::Instance()->MakeSpawner(info);
auto* spawner = dZoneManager::Instance()->GetSpawner(spawnerId);
auto ldfModelBehavior = new LDFData<LWOOBJID>(u"modelBehaviors", 0);
auto userModelID = new LDFData<LWOOBJID>(u"userModelID", id);
auto userModelID = new LDFData<LWOOBJID>(u"userModelID", info.spawnerID);
auto modelType = new LDFData<int>(u"modelType", 2);
auto propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
auto componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
@@ -622,8 +622,8 @@ void PropertyManagementComponent::Load() {
//BBB property models need to have extra stuff set for them:
if (lot == 14) {
LWOOBJID blueprintID = lookupResult->getUInt(10);
blueprintID = GeneralUtils::SetBit(blueprintID, OBJECT_BIT_CHARACTER);
blueprintID = GeneralUtils::SetBit(blueprintID, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
LDFBaseData* ldfBlueprintID = new LDFData<LWOOBJID>(u"blueprintid", blueprintID);
LDFBaseData* componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);

View File

@@ -34,6 +34,7 @@
#include "eRacingTaskParam.h"
#include "eMissionTaskType.h"
#include "eMissionState.h"
#include "eObjectBits.h"
#include "eTriggerEventType.h"
#include <sstream>
@@ -2575,14 +2576,14 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
//We need to get a new ID for our model first:
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t newID) {
LWOOBJID newIDL = newID;
newIDL = GeneralUtils::SetBit(newIDL, OBJECT_BIT_CHARACTER);
newIDL = GeneralUtils::SetBit(newIDL, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(newIDL, eObjectBits::CHARACTER);
GeneralUtils::SetBit(newIDL, eObjectBits::PERSISTENT);
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t blueprintIDSmall) {
blueprintIDSmall = ObjectIDManager::Instance()->GenerateRandomObjectID();
LWOOBJID blueprintID = blueprintIDSmall;
blueprintID = GeneralUtils::SetBit(blueprintID, OBJECT_BIT_CHARACTER);
blueprintID = GeneralUtils::SetBit(blueprintID, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
//We need to get the propertyID: (stolen from Wincent's propertyManagementComp)
const auto& worldId = dZoneManager::Instance()->GetZone()->GetZoneID();

View File

@@ -16,6 +16,7 @@
#include "AssetManager.h"
#include "InventoryComponent.h"
#include "Loot.h"
#include "eObjectBits.h"
#include "eReplicaComponentType.h"
#include "CDBrickIDTableTable.h"
@@ -77,13 +78,13 @@ Item::Item(
LWOOBJID id = ObjectIDManager::GenerateRandomObjectID();
id = GeneralUtils::SetBit(id, OBJECT_BIT_CHARACTER);
id = GeneralUtils::SetBit(id, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(id, eObjectBits::CHARACTER);
GeneralUtils::SetBit(id, eObjectBits::PERSISTENT);
const auto type = static_cast<eItemType>(info->itemType);
if (type == eItemType::MOUNT) {
id = GeneralUtils::SetBit(id, OBJECT_BIT_CLIENT);
GeneralUtils::SetBit(id, eObjectBits::CLIENT);
}
this->id = id;

View File

@@ -75,6 +75,7 @@
#include "eMissionState.h"
#include "TriggerComponent.h"
#include "eServerDisconnectIdentifiers.h"
#include "eObjectBits.h"
#include "eGameMasterLevel.h"
#include "eReplicaComponentType.h"
@@ -1029,8 +1030,8 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
accountId = result->getUInt(1);
characterId = result->getUInt64(2);
characterId = GeneralUtils::SetBit(characterId, OBJECT_BIT_CHARACTER);
characterId = GeneralUtils::SetBit(characterId, OBJECT_BIT_PERSISTENT);
GeneralUtils::SetBit(characterId, eObjectBits::CHARACTER);
GeneralUtils::SetBit(characterId, eObjectBits::PERSISTENT);
}
}