diff --git a/dDatabase/CDClientDatabase/CDClientManager.cpp b/dDatabase/CDClientDatabase/CDClientManager.cpp index 0e05c0b8..e1548db7 100644 --- a/dDatabase/CDClientDatabase/CDClientManager.cpp +++ b/dDatabase/CDClientDatabase/CDClientManager.cpp @@ -40,6 +40,7 @@ #include "CDRailActivatorComponent.h" #include "CDRewardCodesTable.h" #include "CDPetComponentTable.h" +#include "CDMovingPlatformComponentTable.h" #include @@ -110,6 +111,7 @@ DEFINE_TABLE_STORAGE(CDScriptComponentTable); DEFINE_TABLE_STORAGE(CDSkillBehaviorTable); DEFINE_TABLE_STORAGE(CDVendorComponentTable); DEFINE_TABLE_STORAGE(CDZoneTableTable); +DEFINE_TABLE_STORAGE(CDMovingPlatformComponentTable); void CDClientManager::LoadValuesFromDatabase() { if (!CDClientDatabase::isConnected) throw CDClientConnectionException(); diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMovingPlatformComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMovingPlatformComponentTable.cpp index f4331eb2..e6029e67 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMovingPlatformComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMovingPlatformComponentTable.cpp @@ -1,6 +1,7 @@ #include "CDMovingPlatformComponentTable.h" CDMovingPlatformComponentTable::CDMovingPlatformComponentTable() { + auto& entries = GetEntriesMutable(); auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MovingPlatforms"); while (!tableData.eof()) { CDMovingPlatformTableEntry entry; @@ -11,12 +12,13 @@ CDMovingPlatformComponentTable::CDMovingPlatformComponentTable() { entry.platformMove.z = tableData.getFloatField("platformMoveZ", 0.0f); entry.moveTime = tableData.getFloatField("platformMoveTime", -1.0f); - DluAssert(m_Platforms.insert(std::make_pair(tableData.getIntField("id", -1), entry)).second); + DluAssert(entries.insert(std::make_pair(tableData.getIntField("id", -1), entry)).second); tableData.nextRow(); } } void CDMovingPlatformComponentTable::CachePlatformEntry(ComponentID id) { + auto& entries = GetEntriesMutable(); auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM MovingPlatforms WHERE id = ?;"); query.bind(1, static_cast(id)); @@ -30,16 +32,17 @@ void CDMovingPlatformComponentTable::CachePlatformEntry(ComponentID id) { entry.platformMove.z = tableData.getFloatField("platformMoveZ", 0.0f); entry.moveTime = tableData.getFloatField("platformMoveTime", -1.0f); - DluAssert(m_Platforms.insert(std::make_pair(tableData.getIntField("id", -1), entry)).second); + DluAssert(entries.insert(std::make_pair(tableData.getIntField("id", -1), entry)).second); tableData.nextRow(); } } const std::optional CDMovingPlatformComponentTable::GetPlatformEntry(ComponentID id) { - auto itr = m_Platforms.find(id); - if (itr == m_Platforms.end()) { + auto& entries = GetEntriesMutable(); + auto itr = entries.find(id); + if (itr == entries.end()) { CachePlatformEntry(id); - itr = m_Platforms.find(id); + itr = entries.find(id); } - return itr != m_Platforms.end() ? std::make_optional(itr->second) : std::nullopt; + return itr != entries.end() ? std::make_optional(itr->second) : std::nullopt; } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMovingPlatformComponentTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDMovingPlatformComponentTable.h index bcb1d12b..dccac16c 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMovingPlatformComponentTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMovingPlatformComponentTable.h @@ -15,13 +15,11 @@ struct CDMovingPlatformTableEntry { bool platformStartAtEnd; }; -class CDMovingPlatformComponentTable : public CDTable { +class CDMovingPlatformComponentTable : public CDTable> { public: CDMovingPlatformComponentTable(); void CachePlatformEntry(ComponentID id); const std::optional GetPlatformEntry(ComponentID id); -private: - std::map m_Platforms; }; #endif //!__CDMOVINGPLATFORMCOMPONENTTABLE__H__ diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index ae0e616c..ab865d95 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -36,8 +36,8 @@ PlatformSubComponent::PlatformSubComponent(MovingPlatformComponent* parentCompon m_IsDirty = false; m_InReverse = false; m_ShouldStopAtDesiredWaypoint = false; - m_LinearVelocity = NiPoint3::ZERO; - m_AngularVelocity = NiPoint3::ZERO; + m_LinearVelocity = NiPoint3Constant::ZERO; + m_AngularVelocity = NiPoint3Constant::ZERO; m_TimeBasedMovement = false; m_Path = nullptr; } @@ -221,8 +221,8 @@ void PlatformSubComponent::StopPathing() { m_State |= eMovementPlatformState::Stopped; m_State &= ~eMovementPlatformState::Travelling; m_State &= ~eMovementPlatformState::Waiting; - m_LinearVelocity = NiPoint3::ZERO; - m_AngularVelocity = NiPoint3::ZERO; + m_LinearVelocity = NiPoint3Constant::ZERO; + m_AngularVelocity = NiPoint3Constant::ZERO; } //------------- PlatformSubComponent end -------------- @@ -285,7 +285,7 @@ void SimpleMoverPlatformSubComponent::LoadConfigData() { void SimpleMoverPlatformSubComponent::LoadDataFromTemplate() { if (!m_ParentComponent->GetParent()->GetVar(u"dbonly")) return; - auto* movingPlatformTable = CDClientManager::Instance().GetTable(); + auto* movingPlatformTable = CDClientManager::GetTable(); if (movingPlatformTable == nullptr) return; const auto& platformEntry = movingPlatformTable->GetPlatformEntry(m_ParentComponent->GetComponentId()); @@ -324,7 +324,7 @@ void MovingPlatformComponent::LoadConfigData() { AddMovingPlatform(); } if (m_Parent->GetVar(u"platformIsSimpleMover")) { - AddMovingPlatform(NiPoint3::ZERO, false); + AddMovingPlatform(NiPoint3Constant::ZERO, false); } if (m_Parent->GetVar(u"platformIsRotater")) { AddMovingPlatform(); @@ -339,7 +339,7 @@ void MovingPlatformComponent::Update(float deltaTime) { std::for_each(m_Platforms.begin(), m_Platforms.end(), [deltaTime](const std::unique_ptr& platform) { platform->Update(deltaTime); }); } -void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { +void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { // For some reason we need to write this here instead of later on. outBitStream->Write(!m_Platforms.empty()); @@ -370,7 +370,7 @@ void MovingPlatformComponent::OnQuickBuildInitilized() { StopPathing(); } -void MovingPlatformComponent::OnCompleteRebuild() { +void MovingPlatformComponent::OnCompleteQuickBuild() { if (m_NoAutoStart) return; StartPathing(); diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index d0a7dfa2..4cd19573 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -389,8 +389,8 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd bitStream.Write(subComponent.GetPosition().y); bitStream.Write(subComponent.GetPosition().z); - bitStream.Write(subComponent.GetRotation() != NiQuaternion::IDENTITY); - if (subComponent.GetRotation() != NiQuaternion::IDENTITY) { + bitStream.Write(subComponent.GetRotation() != NiQuaternionConstant::IDENTITY); + if (subComponent.GetRotation() != NiQuaternionConstant::IDENTITY) { bitStream.Write(subComponent.GetRotation().x); bitStream.Write(subComponent.GetRotation().y); bitStream.Write(subComponent.GetRotation().z); diff --git a/dScripts/02_server/Map/General/PropertyPlatform.cpp b/dScripts/02_server/Map/General/PropertyPlatform.cpp index de06db0c..eee2a6c2 100644 --- a/dScripts/02_server/Map/General/PropertyPlatform.cpp +++ b/dScripts/02_server/Map/General/PropertyPlatform.cpp @@ -3,15 +3,15 @@ #include "GameMessages.h" #include "MovingPlatformComponent.h" -void PropertyPlatform::OnRebuildComplete(Entity* self, Entity* target) { +void PropertyPlatform::OnQuickBuildComplete(Entity* self, Entity* target) { GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS , static_cast(eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint), true, 0, 0, 0); } void PropertyPlatform::OnUse(Entity* self, Entity* user) { - auto* rebuildComponent = self->GetComponent(); - if (rebuildComponent != nullptr && rebuildComponent->GetState() == eRebuildState::COMPLETED) { + auto* rebuildComponent = self->GetComponent(); + if (rebuildComponent != nullptr && rebuildComponent->GetState() == eQuickBuildState::COMPLETED) { GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling, true, 0, 1, 1); diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 44788a64..1efaeb7a 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -327,11 +327,13 @@ void SGCannon::DoSpawnTimerFunc(Entity* self, const std::string& name) { // Save the enemy and tell it to start pathing if (enemy != nullptr) { const_cast&>(self->GetVar>(SpawnedObjects)).push_back(enemy->GetObjectID()); - GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS); + GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling); } } } +#pragma warning("TODO: FIX THE ABOVE GM CALL") + void SGCannon::EndGameBufferTimerFunc(Entity* self) { RecordPlayerScore(self); StopGame(self, false); @@ -381,9 +383,7 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { auto* enemy = Game::entityManager->CreateEntity(info, nullptr, self); Game::entityManager->ConstructEntity(enemy); - auto* movementAI = new MovementAIComponent(enemy, {}); - - enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI); + auto* movementAI = enemy->AddComponent({}); movementAI->SetMaxSpeed(toSpawn.initialSpeed); movementAI->SetCurrentSpeed(toSpawn.initialSpeed); diff --git a/tests/dGameTests/GameDependencies.cpp b/tests/dGameTests/GameDependencies.cpp index da92ade7..1b3d0d6e 100644 --- a/tests/dGameTests/GameDependencies.cpp +++ b/tests/dGameTests/GameDependencies.cpp @@ -15,12 +15,12 @@ namespace Game { } void GameDependenciesTest::SetUpDependencies() { - info.pos = NiPoint3::ZERO; - info.rot = NiQuaternion::IDENTITY; + info.pos = NiPoint3Constant::ZERO; + info.rot = NiQuaternionConstant::IDENTITY; info.scale = 1.0f; info.spawner = nullptr; info.lot = 999; - Game::logger = new dLogger("./testing.log", true, true); + Game::logger = new Logger("./testing.log", true, true); Game::server = new dServerMock(); Game::config = new dConfig("worldconfig.ini"); Game::entityManager = new EntityManager(); diff --git a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp index 1ce8c687..e809cc84 100644 --- a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp @@ -57,12 +57,11 @@ protected: baseEntity = std::make_unique(15, GameDependenciesTest::info); - auto* simplePhysicsComponent = new SimplePhysicsComponent(1, baseEntity.get()); - baseEntity->AddComponent(SimplePhysicsComponent::ComponentType, simplePhysicsComponent); - auto* movingPlatformComponent = new MovingPlatformComponent(baseEntity.get(), path.pathName); + auto* simplePhysicsComponent = baseEntity->AddComponent(1); + auto* movingPlatformComponent = baseEntity->AddComponent("ExamplePath"); + new MovingPlatformComponent(baseEntity.get(), path.pathName); movingPlatformComponent->LoadConfigData(); movingPlatformComponent->LoadDataFromTemplate(); - baseEntity->AddComponent(MovingPlatformComponent::ComponentType, movingPlatformComponent); } void TearDown() override { @@ -215,8 +214,7 @@ protected: void TestSerialization() { auto* movingPlatformComponent = baseEntity->GetComponent(); ASSERT_NE(movingPlatformComponent, nullptr); - uint32_t flags = 0; - movingPlatformComponent->Serialize(&bitStream, true, flags); + movingPlatformComponent->Serialize(&bitStream, true); DeserializeMovingPlatformComponent(); } };