Skip to content

Commit

Permalink
refact(Direction): make DirectionsToVect returns vec3i
Browse files Browse the repository at this point in the history
  • Loading branch information
Insineer committed Oct 30, 2019
1 parent 9b1f3ff commit ad0d11f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion OSS13 Client/Sources/Graphics/TileGrid/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void Object::ResetShiftingState() {
}

void Object::ReverseShifting(uf::Direction direction) {
uf::vec2i directionVect = uf::DirectionToVect(direction);
uf::vec2i directionVect = uf::DirectionToVect(direction).xy();
if (directionVect.x) moveIntent.x = 0, moveIntentApproved.x = 0;
if (directionVect.y) moveIntent.y = 0, moveIntentApproved.y = 0;
shift -= directionVect;
Expand Down
4 changes: 2 additions & 2 deletions OSS13 Client/Sources/Graphics/TileGrid/TileGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void TileGrid::SetMoveIntentObject(uint id, uf::Direction direction) {
auto iter = objects.find(id);
if (objects.find(id) != objects.end()) {
Object *obj = iter->second.get();
uf::vec2i dir = uf::DirectionToVect(direction);
uf::vec2i dir = uf::DirectionToVect(direction).xy();
obj->SetMoveIntent(dir, true);
return;
}
Expand All @@ -445,7 +445,7 @@ void TileGrid::MoveObject(uint id, uf::Direction direction, float speed) {
auto iter = objects.find(id);
if (objects.find(id) != objects.end()) {
Object *obj = iter->second.get();
uf::vec2i dir = uf::DirectionToVect(direction);
uf::vec2i dir = uf::DirectionToVect(direction).xy();

Tile *lastTile = obj->GetTile();
if (!lastTile) {
Expand Down
2 changes: 1 addition & 1 deletion OSS13 Server/Sources/Player/PlayerCommandsProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void PlayerCommandsProcessor::ProcessCommand(network::protocol::Command &general
void PlayerCommandsProcessor::commandProcessor_MoveCommand(network::protocol::client::MoveCommand &command) {
auto control = player->GetControl();
if (control) {
control->MoveCommand(uf::DirectionToVect(command.direction));
control->MoveCommand(uf::DirectionToVect(command.direction).xy());
}
}

Expand Down
2 changes: 1 addition & 1 deletion OSS13 Server/Sources/World/Camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void Camera::UpdateView(std::chrono::microseconds timeElapsed) {
visibleObjects.insert(diff->objId);
} else if (auto *diff = dynamic_cast<network::protocol::MoveDiff *>(generalDiff.get())) {
if (visibleObjects.find(diff->objId) == visibleObjects.end()) {
apos to = apos(object->GetPosition() + DirectionToVect(diff->direction), 0);
apos to = apos(object->GetPosition() + DirectionToVect(diff->direction).xy(), 0);
auto addDiff = std::make_shared<network::protocol::AddDiff>();
addDiff->objId = diff->objId;
addDiff->objectInfo = object->GetObjectInfo();
Expand Down
26 changes: 15 additions & 11 deletions SharedLibrary/Sources/Shared/Geometry/Direction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,36 @@ Direction VectToDirectionDetail(vec2<T> vector) {
Direction VectToDirection(vec2f vector) { return VectToDirectionDetail(vector); }
Direction VectToDirection(vec3f vector) { return VectToDirectionDetail(vector.xy()); }

vec2i DirectionToVect(Direction direction) {
vec3i DirectionToVect(Direction direction) {
switch (direction) {
case Direction::SOUTH:
return {0, 1};
return {0, 1, 0};
case Direction::WEST:
return {-1, 0};
return {-1, 0, 0};
case Direction::NORTH:
return {0, -1};
return {0, -1, 0};
case Direction::EAST:
return {1, 0};
return {1, 0, 0};
case Direction::SOUTH_WEST:
return {-1, 1};
return {-1, 1, 0};
case Direction::NORTH_WEST:
return {-1, -1};
return {-1, -1, 0};
case Direction::NORTH_EAST:
return {1, -1};
return {1, -1, 0};
case Direction::SOUTH_EAST:
return {1, 1};
return {1, 1, 0};
case Direction::BOTTOM:
return {0, 0, -1};
case Direction::TOP:
return {0, 0, 1};
default:
return {0, 0};
return {0, 0, 0};
}
}

Angle DirectionToAngle(Direction direction) {
EXPECT(direction != Direction::NONE);
return (DirectionToVect(direction) * -1).angle();
return (DirectionToVect(direction).xy() * -1).angle();
}

Direction InvertDirection(Direction direction) {
Expand Down
2 changes: 1 addition & 1 deletion SharedLibrary/Sources/Shared/Geometry/Direction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool IsPureDirection(Direction direction);

Direction VectToDirection(vec2f);
Direction VectToDirection(vec3f);
vec2i DirectionToVect(Direction);
vec3i DirectionToVect(Direction);
Angle DirectionToAngle(Direction);

Direction InvertDirection(Direction);
Expand Down

0 comments on commit ad0d11f

Please sign in to comment.