branch back to working state

This commit is contained in:
David Markowitz 2024-02-10 19:23:35 -08:00
parent 790505ba6f
commit 944d3e1bac
9 changed files with 36 additions and 35 deletions

View File

@ -40,6 +40,7 @@
#include "CDRailActivatorComponent.h"
#include "CDRewardCodesTable.h"
#include "CDPetComponentTable.h"
#include "CDMovingPlatformComponentTable.h"
#include <exception>
@ -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();

View File

@ -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<int32_t>(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<CDMovingPlatformTableEntry> 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<CDMovingPlatformTableEntry>(itr->second) : std::nullopt;
return itr != entries.end() ? std::make_optional<CDMovingPlatformTableEntry>(itr->second) : std::nullopt;
}

View File

@ -15,13 +15,11 @@ struct CDMovingPlatformTableEntry {
bool platformStartAtEnd;
};
class CDMovingPlatformComponentTable : public CDTable<CDMovingPlatformComponentTable> {
class CDMovingPlatformComponentTable : public CDTable<CDMovingPlatformComponentTable, std::map<ComponentID, CDMovingPlatformTableEntry>> {
public:
CDMovingPlatformComponentTable();
void CachePlatformEntry(ComponentID id);
const std::optional<CDMovingPlatformTableEntry> GetPlatformEntry(ComponentID id);
private:
std::map<ComponentID, CDMovingPlatformTableEntry> m_Platforms;
};
#endif //!__CDMOVINGPLATFORMCOMPONENTTABLE__H__

View File

@ -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<bool>(u"dbonly")) return;
auto* movingPlatformTable = CDClientManager::Instance().GetTable<CDMovingPlatformComponentTable>();
auto* movingPlatformTable = CDClientManager::GetTable<CDMovingPlatformComponentTable>();
if (movingPlatformTable == nullptr) return;
const auto& platformEntry = movingPlatformTable->GetPlatformEntry(m_ParentComponent->GetComponentId());
@ -324,7 +324,7 @@ void MovingPlatformComponent::LoadConfigData() {
AddMovingPlatform<MoverPlatformSubComponent>();
}
if (m_Parent->GetVar<bool>(u"platformIsSimpleMover")) {
AddMovingPlatform<SimpleMoverPlatformSubComponent>(NiPoint3::ZERO, false);
AddMovingPlatform<SimpleMoverPlatformSubComponent>(NiPoint3Constant::ZERO, false);
}
if (m_Parent->GetVar<bool>(u"platformIsRotater")) {
AddMovingPlatform<RotatorPlatformSubComponent>();
@ -339,7 +339,7 @@ void MovingPlatformComponent::Update(float deltaTime) {
std::for_each(m_Platforms.begin(), m_Platforms.end(), [deltaTime](const std::unique_ptr<PlatformSubComponent>& 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();

View File

@ -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);

View File

@ -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>(eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint),
true, 0, 0, 0);
}
void PropertyPlatform::OnUse(Entity* self, Entity* user) {
auto* rebuildComponent = self->GetComponent<RebuildComponent>();
if (rebuildComponent != nullptr && rebuildComponent->GetState() == eRebuildState::COMPLETED) {
auto* rebuildComponent = self->GetComponent<QuickBuildComponent>();
if (rebuildComponent != nullptr && rebuildComponent->GetState() == eQuickBuildState::COMPLETED) {
GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling, true, 0,
1, 1);

View File

@ -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<std::vector<LWOOBJID>&>(self->GetVar<std::vector<LWOOBJID>>(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<MovementAIComponent, MovementAIInfo>({});
movementAI->SetMaxSpeed(toSpawn.initialSpeed);
movementAI->SetCurrentSpeed(toSpawn.initialSpeed);

View File

@ -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();

View File

@ -57,12 +57,11 @@ protected:
baseEntity = std::make_unique<Entity>(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<SimplePhysicsComponent>(1);
auto* movingPlatformComponent = baseEntity->AddComponent<MovingPlatformComponent>("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<MovingPlatformComponent>();
ASSERT_NE(movingPlatformComponent, nullptr);
uint32_t flags = 0;
movingPlatformComponent->Serialize(&bitStream, true, flags);
movingPlatformComponent->Serialize(&bitStream, true);
DeserializeMovingPlatformComponent();
}
};