Browse Source
Added a simple Position class which the world will eventually use. I also did some small refactoring here and there in HTNs and updated tests.combatComponentRefactor

12 changed files with 265 additions and 74 deletions
@ -0,0 +1,51 @@ |
|||
#include <iostream> |
|||
|
|||
#define CATCH_CONFIG_MAIN |
|||
#include "../../thirdParty/Catch/single_include/catch.hpp" |
|||
|
|||
#include "../world/Position.hpp" |
|||
|
|||
TEST_CASE("Position and GlobalPosition") |
|||
{ |
|||
SECTION("Position Initialization") |
|||
{ |
|||
gv::Position position; |
|||
REQUIRE((position.X == 0.f && position.Y == 0.f && position.Z == 0.f)); |
|||
|
|||
gv::Position position2(1.f, 1.f, 1.f); |
|||
REQUIRE((position2.X == 1.f && position2.Y == 1.f && position2.Z == 1.f)); |
|||
} |
|||
|
|||
SECTION("Position Array Accessor") |
|||
{ |
|||
gv::Position position(1.f, 2.f, 3.f); |
|||
REQUIRE( |
|||
(position.X == position[0] && position.Y == position[1] && position.Z == position[2])); |
|||
} |
|||
|
|||
SECTION("Position Equals") |
|||
{ |
|||
gv::Position a(1.f, 2.f, 3.f); |
|||
gv::Position b(1.08f, 2.08f, 3.08f); |
|||
REQUIRE(a.Equals(b, 0.1f)); |
|||
REQUIRE(!a.Equals(b, 0.01f)); |
|||
} |
|||
|
|||
SECTION("Position Const Operators") |
|||
{ |
|||
gv::Position a(1.f, 2.f, 3.f); |
|||
gv::Position b(1.f, 2.f, 3.f); |
|||
gv::Position expectedResult(2.f, 4.f, 6.f); |
|||
gv::Position result = a + b; |
|||
REQUIRE(result.Equals(expectedResult, 0.01f)); |
|||
} |
|||
|
|||
SECTION("Position Modifier Operators") |
|||
{ |
|||
gv::Position a(1.f, 2.f, 3.f); |
|||
gv::Position b(1.f, 2.f, 3.f); |
|||
gv::Position expectedResult(2.f, 4.f, 6.f); |
|||
a += b; |
|||
REQUIRE(a.Equals(expectedResult, 0.01f)); |
|||
} |
|||
} |
@ -0,0 +1,5 @@ |
|||
SubDir . src world ; |
|||
|
|||
Library libGalaWorld : Position.cpp ; |
|||
|
|||
MakeLocate libGalaWorld.a : lib ; |
@ -0,0 +1,101 @@ |
|||
#include "Position.hpp" |
|||
#include <cmath> |
|||
|
|||
namespace gv |
|||
{ |
|||
Position::Position(float x, float y, float z) : X(x), Y(y), Z(z) |
|||
{ |
|||
} |
|||
|
|||
bool Position::Equals(const Position& otherPosition, float tolerance) const |
|||
{ |
|||
return (fabs(X - otherPosition.X) <= tolerance && fabs(Y - otherPosition.Y) <= tolerance && |
|||
fabs(Z - otherPosition.Z) <= tolerance); |
|||
} |
|||
|
|||
float& Position::operator[](int index) |
|||
{ |
|||
switch (index) |
|||
{ |
|||
case 0: |
|||
return X; |
|||
case 1: |
|||
return Y; |
|||
case 2: |
|||
return Z; |
|||
} |
|||
return X; |
|||
} |
|||
|
|||
Position Position::operator+(const Position& otherPosition) const |
|||
{ |
|||
Position newPosition(*this); |
|||
newPosition.X += otherPosition.X; |
|||
newPosition.Y += otherPosition.Y; |
|||
newPosition.Z += otherPosition.Z; |
|||
return newPosition; |
|||
} |
|||
|
|||
Position Position::operator-(const Position& otherPosition) const |
|||
{ |
|||
Position newPosition(*this); |
|||
newPosition.X -= otherPosition.X; |
|||
newPosition.Y -= otherPosition.Y; |
|||
newPosition.Z -= otherPosition.Z; |
|||
return newPosition; |
|||
} |
|||
|
|||
Position Position::operator*(const Position& otherPosition) const |
|||
{ |
|||
Position newPosition(*this); |
|||
newPosition.X *= otherPosition.X; |
|||
newPosition.Y *= otherPosition.Y; |
|||
newPosition.Z *= otherPosition.Z; |
|||
return newPosition; |
|||
} |
|||
|
|||
Position Position::operator/(const Position& otherPosition) const |
|||
{ |
|||
Position newPosition(*this); |
|||
newPosition.X /= otherPosition.X; |
|||
newPosition.Y /= otherPosition.Y; |
|||
newPosition.Z /= otherPosition.Z; |
|||
return newPosition; |
|||
} |
|||
|
|||
Position& Position::operator+=(const Position& otherPosition) |
|||
{ |
|||
X += otherPosition.X; |
|||
Y += otherPosition.Y; |
|||
Z += otherPosition.Z; |
|||
return *this; |
|||
} |
|||
|
|||
Position& Position::operator-=(const Position& otherPosition) |
|||
{ |
|||
X -= otherPosition.X; |
|||
Y -= otherPosition.Y; |
|||
Z -= otherPosition.Z; |
|||
return *this; |
|||
} |
|||
|
|||
Position& Position::operator*=(const Position& otherPosition) |
|||
{ |
|||
X *= otherPosition.X; |
|||
Y *= otherPosition.Y; |
|||
Z *= otherPosition.Z; |
|||
return *this; |
|||
} |
|||
|
|||
Position& Position::operator/=(const Position& otherPosition) |
|||
{ |
|||
X /= otherPosition.X; |
|||
Y /= otherPosition.Y; |
|||
Z /= otherPosition.Z; |
|||
return *this; |
|||
} |
|||
|
|||
GlobalPosition::GlobalPosition(Position& localPosition) : LocalPosition(localPosition) |
|||
{ |
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
#pragma once |
|||
|
|||
namespace gv |
|||
{ |
|||
struct Position |
|||
{ |
|||
float X = 0.f; |
|||
float Y = 0.f; |
|||
float Z = 0.f; |
|||
|
|||
Position() = default; |
|||
Position(float x, float y, float z); |
|||
|
|||
bool Equals(const Position& otherPosition, float tolerance) const; |
|||
|
|||
float& operator[](int index); |
|||
|
|||
Position operator+(const Position& otherPosition) const; |
|||
Position operator-(const Position& otherPosition) const; |
|||
Position operator*(const Position& otherPosition) const; |
|||
Position operator/(const Position& otherPosition) const; |
|||
|
|||
Position& operator+=(const Position& otherPosition); |
|||
Position& operator-=(const Position& otherPosition); |
|||
Position& operator*=(const Position& otherPosition); |
|||
Position& operator/=(const Position& otherPosition); |
|||
}; |
|||
|
|||
struct GlobalPosition |
|||
{ |
|||
Position LocalPosition; |
|||
// Will be added once chunks/world is figured out
|
|||
// Position ChunkPosition;
|
|||
|
|||
GlobalPosition() = default; |
|||
GlobalPosition(Position& localPosition); |
|||
}; |
|||
}; |
Loading…
Reference in new issue