Merge branch 'main' into movingPlatformWork

This commit is contained in:
David Markowitz
2024-02-10 19:10:55 -08:00
810 changed files with 18865 additions and 15976 deletions

View File

@@ -1,6 +1,8 @@
set(DCOMPONENTS_TESTS
"DestroyableComponentTests.cpp"
"MovingPlatformComponentTests.cpp"
"PetComponentTests.cpp"
"SimplePhysicsComponentTests.cpp"
)
# Get the folder name and prepend it to the files above

View File

@@ -16,8 +16,7 @@ protected:
void SetUp() override {
SetUpDependencies();
baseEntity = new Entity(15, GameDependenciesTest::info);
destroyableComponent = new DestroyableComponent(baseEntity);
baseEntity->AddComponent(eReplicaComponentType::DESTROYABLE, destroyableComponent);
destroyableComponent = baseEntity->AddComponent<DestroyableComponent>();
// Initialize some values to be not default
destroyableComponent->SetMaxHealth(12345.0f);
destroyableComponent->SetHealth(23);
@@ -37,11 +36,19 @@ protected:
}
};
TEST_F(DestroyableTest, PlacementNewAddComponentTest) {
ASSERT_NE(destroyableComponent, nullptr);
ASSERT_EQ(destroyableComponent->GetArmor(), 7);
baseEntity->AddComponent<DestroyableComponent>();
ASSERT_NE(baseEntity->GetComponent<DestroyableComponent>(), nullptr);
ASSERT_EQ(destroyableComponent->GetArmor(), 0);
}
/**
* Test Construction of a DestroyableComponent
*/
TEST_F(DestroyableTest, DestroyableComponentSerializeConstructionTest) {
destroyableComponent->Serialize(&bitStream, true, flags);
destroyableComponent->Serialize(&bitStream, true);
// Assert that the full number of bits are present
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 748);
{
@@ -171,7 +178,7 @@ TEST_F(DestroyableTest, DestroyableComponentSerializeTest) {
destroyableComponent->SetMaxHealth(1233.0f);
// Now we test a serialization for correctness.
destroyableComponent->Serialize(&bitStream, false, flags);
destroyableComponent->Serialize(&bitStream, false);
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 422);
{
// Now read in the full serialized BitStream
@@ -318,9 +325,7 @@ TEST_F(DestroyableTest, DestroyableComponentFactionTest) {
TEST_F(DestroyableTest, DestroyableComponentValiditiyTest) {
auto* enemyEntity = new Entity(19, info);
auto* enemyDestroyableComponent = new DestroyableComponent(enemyEntity);
enemyEntity->AddComponent(eReplicaComponentType::DESTROYABLE, enemyDestroyableComponent);
enemyDestroyableComponent->AddFactionNoLookup(16);
enemyEntity->AddComponent<DestroyableComponent>()->AddFactionNoLookup(16);
destroyableComponent->AddEnemyFaction(16);
EXPECT_TRUE(destroyableComponent->IsEnemy(enemyEntity));
EXPECT_FALSE(destroyableComponent->IsFriend(enemyEntity));
@@ -531,3 +536,22 @@ TEST_F(DestroyableTest, DestroyableComponentImmunityTest) {
}
/**
* Test the Damage cooldown timer of DestroyableComponent
*/
TEST_F(DestroyableTest, DestroyableComponentDamageCooldownTest) {
// Test the damage immune timer state (anything above 0.0f)
destroyableComponent->SetDamageCooldownTimer(1.0f);
EXPECT_FLOAT_EQ(destroyableComponent->GetDamageCooldownTimer(), 1.0f);
ASSERT_TRUE(destroyableComponent->IsCooldownImmune());
// Test that the Update() function correctly decrements the damage cooldown timer
destroyableComponent->Update(0.5f);
EXPECT_FLOAT_EQ(destroyableComponent->GetDamageCooldownTimer(), 0.5f);
ASSERT_TRUE(destroyableComponent->IsCooldownImmune());
// Test the non damage immune timer state (anything below or equal to 0.0f)
destroyableComponent->SetDamageCooldownTimer(0.0f);
EXPECT_FLOAT_EQ(destroyableComponent->GetDamageCooldownTimer(), 0.0f);
ASSERT_FALSE(destroyableComponent->IsCooldownImmune());
}

View File

@@ -0,0 +1,43 @@
#include "GameDependencies.h"
#include <gtest/gtest.h>
#include "BitStream.h"
#include "PetComponent.h"
#include "Entity.h"
#include "eReplicaComponentType.h"
#include "ePetAbilityType.h"
#include "eStateChangeType.h"
class PetTest : public GameDependenciesTest {
protected:
Entity* baseEntity;
PetComponent* petComponent;
CBITSTREAM
void SetUp() override {
SetUpDependencies();
// Set up entity and pet component
baseEntity = new Entity(15, GameDependenciesTest::info);
petComponent = baseEntity->AddComponent<PetComponent>(1);
// Initialize some values to be not default
}
void TearDown() override {
delete baseEntity;
TearDownDependencies();
}
};
TEST_F(PetTest, PlacementNewAddComponentTest) {
// Test adding component
ASSERT_NE(petComponent, nullptr);
baseEntity->AddComponent<PetComponent>(1);
ASSERT_NE(baseEntity->GetComponent<PetComponent>(), nullptr);
// Test getting initial status
ASSERT_EQ(petComponent->GetParent()->GetObjectID(), 15);
ASSERT_EQ(petComponent->GetAbility(), ePetAbilityType::Invalid);
}

View File

@@ -0,0 +1,153 @@
#include "GameDependencies.h"
#include <gtest/gtest.h>
#include "BitStream.h"
#include "SimplePhysicsComponent.h"
#include "Entity.h"
#include "eReplicaComponentType.h"
#include "eStateChangeType.h"
class SimplePhysicsTest : public GameDependenciesTest {
protected:
std::unique_ptr<Entity> baseEntity;
SimplePhysicsComponent* simplePhysicsComponent;
CBITSTREAM;
void SetUp() override {
SetUpDependencies();
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
simplePhysicsComponent = baseEntity->AddComponent<SimplePhysicsComponent>(1);
simplePhysicsComponent->SetClimbableType(eClimbableType::CLIMBABLE_TYPE_WALL);
simplePhysicsComponent->SetPosition(NiPoint3(1.0f, 2.0f, 3.0f));
simplePhysicsComponent->SetRotation(NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
simplePhysicsComponent->SetVelocity(NiPoint3(5.0f, 6.0f, 7.0f));
simplePhysicsComponent->SetAngularVelocity(NiPoint3(5.0f, 6.0f, 7.0f));
simplePhysicsComponent->SetPhysicsMotionState(2);
}
void TearDown() override {
TearDownDependencies();
}
};
TEST_F(SimplePhysicsTest, SimplePhysicsSerializeTest) {
simplePhysicsComponent->Serialize(&bitStream, false);
constexpr uint32_t sizeOfStream = 3 + BYTES_TO_BITS(3 * sizeof(NiPoint3)) + BYTES_TO_BITS(1 * sizeof(NiQuaternion)) + 1 * BYTES_TO_BITS(sizeof(uint32_t));
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), sizeOfStream);
bool dirtyVelocityFlag;
bitStream.Read(dirtyVelocityFlag);
ASSERT_EQ(dirtyVelocityFlag, true);
NiPoint3 velocity;
bitStream.Read(velocity.x);
bitStream.Read(velocity.y);
bitStream.Read(velocity.z);
ASSERT_EQ(velocity, NiPoint3(5.0f, 6.0f, 7.0f));
NiPoint3 angularVelocity;
bitStream.Read(angularVelocity.x);
bitStream.Read(angularVelocity.y);
bitStream.Read(angularVelocity.z);
ASSERT_EQ(angularVelocity, NiPoint3(5.0f, 6.0f, 7.0f));
bool dirtyPhysicsMotionStateFlag;
bitStream.Read(dirtyPhysicsMotionStateFlag);
ASSERT_EQ(dirtyPhysicsMotionStateFlag, true);
uint32_t physicsMotionState;
bitStream.Read(physicsMotionState);
ASSERT_EQ(physicsMotionState, 2.0f);
bool dirtyPositionFlag;
bitStream.Read(dirtyPositionFlag);
ASSERT_EQ(dirtyPositionFlag, true);
NiPoint3 position;
bitStream.Read(position.x);
bitStream.Read(position.y);
bitStream.Read(position.z);
ASSERT_EQ(position, NiPoint3(1.0f, 2.0f, 3.0f));
NiQuaternion rotation;
bitStream.Read(rotation.x);
bitStream.Read(rotation.y);
bitStream.Read(rotation.z);
bitStream.Read(rotation.w);
ASSERT_EQ(rotation, NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
}
TEST_F(SimplePhysicsTest, SimplePhysicsConstructionTest) {
simplePhysicsComponent->Serialize(&bitStream, true);
constexpr uint32_t sizeOfStream = 4 + BYTES_TO_BITS(1 * sizeof(int32_t)) + BYTES_TO_BITS(3 * sizeof(NiPoint3)) + BYTES_TO_BITS(1 * sizeof(NiQuaternion)) + 1 * BYTES_TO_BITS(sizeof(uint32_t));
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), sizeOfStream);
bool dirtyClimbableTypeFlag;
bitStream.Read(dirtyClimbableTypeFlag);
ASSERT_EQ(dirtyClimbableTypeFlag, true);
int32_t climbableType;
bitStream.Read(climbableType);
ASSERT_EQ(climbableType, 2);
bool dirtyVelocityFlag;
bitStream.Read(dirtyVelocityFlag);
ASSERT_EQ(dirtyVelocityFlag, true);
NiPoint3 velocity;
bitStream.Read(velocity.x);
bitStream.Read(velocity.y);
bitStream.Read(velocity.z);
ASSERT_EQ(velocity, NiPoint3(5.0f, 6.0f, 7.0f));
NiPoint3 angularVelocity;
bitStream.Read(angularVelocity.x);
bitStream.Read(angularVelocity.y);
bitStream.Read(angularVelocity.z);
ASSERT_EQ(angularVelocity, NiPoint3(5.0f, 6.0f, 7.0f));
bool dirtyPhysicsMotionStateFlag;
bitStream.Read(dirtyPhysicsMotionStateFlag);
ASSERT_EQ(dirtyPhysicsMotionStateFlag, true);
uint32_t physicsMotionState;
bitStream.Read(physicsMotionState);
ASSERT_EQ(physicsMotionState, 2.0f);
bool dirtyPositionFlag;
bitStream.Read(dirtyPositionFlag);
ASSERT_EQ(dirtyPositionFlag, true);
NiPoint3 position;
bitStream.Read(position.x);
bitStream.Read(position.y);
bitStream.Read(position.z);
ASSERT_EQ(position, NiPoint3(1.0f, 2.0f, 3.0f));
NiQuaternion rotation;
bitStream.Read(rotation.x);
bitStream.Read(rotation.y);
bitStream.Read(rotation.z);
bitStream.Read(rotation.w);
ASSERT_EQ(rotation, NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
}
TEST_F(SimplePhysicsTest, SimplePhysicsGettersAndSettersTest) {
ASSERT_EQ(simplePhysicsComponent->GetClimabbleType(), eClimbableType::CLIMBABLE_TYPE_WALL);
ASSERT_EQ(simplePhysicsComponent->GetPosition(), NiPoint3(1.0f, 2.0f, 3.0f));
ASSERT_EQ(simplePhysicsComponent->GetRotation(), NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
ASSERT_EQ(simplePhysicsComponent->GetVelocity(), NiPoint3(5.0f, 6.0f, 7.0f));
ASSERT_EQ(simplePhysicsComponent->GetAngularVelocity(), NiPoint3(5.0f, 6.0f, 7.0f));
ASSERT_EQ(simplePhysicsComponent->GetPhysicsMotionState(), 2);
simplePhysicsComponent->SetClimbableType(eClimbableType::CLIMBABLE_TYPE_LADDER);
simplePhysicsComponent->SetPosition(NiPoint3(4.0f, 5.0f, 6.0f));
simplePhysicsComponent->SetRotation(NiQuaternion(4.0f, 5.0f, 6.0f, 7.0f));
simplePhysicsComponent->SetVelocity(NiPoint3(6.0f, 7.0f, 8.0f));
simplePhysicsComponent->SetAngularVelocity(NiPoint3(6.0f, 7.0f, 8.0f));
simplePhysicsComponent->SetPhysicsMotionState(3);
ASSERT_EQ(simplePhysicsComponent->GetClimabbleType(), eClimbableType::CLIMBABLE_TYPE_LADDER);
ASSERT_EQ(simplePhysicsComponent->GetPosition(), NiPoint3(4.0f, 5.0f, 6.0f));
ASSERT_EQ(simplePhysicsComponent->GetRotation(), NiQuaternion(4.0f, 5.0f, 6.0f, 7.0f));
ASSERT_EQ(simplePhysicsComponent->GetVelocity(), NiPoint3(6.0f, 7.0f, 8.0f));
ASSERT_EQ(simplePhysicsComponent->GetAngularVelocity(), NiPoint3(6.0f, 7.0f, 8.0f));
ASSERT_EQ(simplePhysicsComponent->GetPhysicsMotionState(), 3);
}