From 298b2eeb77817f2fabac0b466b951da6eead32e6 Mon Sep 17 00:00:00 2001 From: James Ball Date: Sun, 10 Sep 2023 10:53:50 +0100 Subject: [PATCH] Fix BlockingQueue implementation --- Source/concurrency/BlockingQueue.h | 4 ++-- Source/obj/Camera.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/concurrency/BlockingQueue.h b/Source/concurrency/BlockingQueue.h index 574c29f..cbca751 100644 --- a/Source/concurrency/BlockingQueue.h +++ b/Source/concurrency/BlockingQueue.h @@ -35,7 +35,7 @@ public: { std::unique_lock lk(mutex); not_full.wait(lk, [this]() { return size < content.size() || killed; }); - content[head] = std::move(item); + content[(head + size) % content.size()] = std::move(item); size++; } not_empty.notify_one(); @@ -47,7 +47,7 @@ public: if (size == content.size()) { return false; } - content[head] = std::move(item); + content[(head + size) % content.size()] = std::move(item); size++; } not_empty.notify_one(); diff --git a/Source/obj/Camera.cpp b/Source/obj/Camera.cpp index 2153938..282a033 100644 --- a/Source/obj/Camera.cpp +++ b/Source/obj/Camera.cpp @@ -7,8 +7,15 @@ Camera::Camera(double focalLength, double x, double y, double z) : focalLength(f std::vector> Camera::draw(WorldObject& object) { std::vector> shapes; object.nextFrame(); + Line3D* prevLine = nullptr; + Vector2 prevVertex; for (auto& edge : object.edges) { - Vector2 start = project(object.rotateX, object.rotateY, object.rotateZ, edge.x1, edge.y1, edge.z1); + Vector2 start; + if (prevLine != nullptr && prevLine->x2 == edge.x1 && prevLine->y2 == edge.y1 && prevLine->z2 == edge.z1) { + start = prevVertex; + } else { + start = project(object.rotateX, object.rotateY, object.rotateZ, edge.x1, edge.y1, edge.z1); + } Vector2 end = project(object.rotateX, object.rotateY, object.rotateZ, edge.x2, edge.y2, edge.z2); shapes.push_back(std::make_unique(start.x, start.y, end.x, end.y));