Skip to content

Commit

Permalink
v3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
F-Mu committed Dec 18, 2022
1 parent 7fb1752 commit 400794d
Show file tree
Hide file tree
Showing 27 changed files with 754 additions and 191 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,26 @@ https://github.com/blurrypiano/littleVulkanEngine/tree/master

**v3.2**

+ 使粒子效果更好看,包括粒子颜色渐变,增加粒子以抗锯齿(我真的在努力做火焰效果了,其实也许红色拖影更好看?)
+ 使粒子效果更好看,包括粒子颜色渐变,增加粒子以抗锯齿(真的在努力做火焰效果了,其实也许红色拖影更好看?)

+ 修复了Task乱飞的bug(大概,此bug 100个Task也不一定会出现,所以未知是否修好
+ 修复了Task乱飞的bug(没修好

+ 修改移动逻辑

**v3.3**

+ 添加数字组件,可以在睡眠任务中计数,并实现数字渐变效果

+ 调整项目结构

+ 再次宣称修复好了Task乱飞的bug(因为不知道bug产生的原因,只能限制各种条件)

+ 修改Pipeline逻辑,组件中bind,RenderPass中渲染

**待实现(可能也不会实现):**

+ 粒子分为不动粒子(不需要logic tick)和运动粒子,优化性能

+ 更好的异步执行(Job System)

+ 尝试更更好的分层
Expand All @@ -82,6 +94,12 @@ https://github.com/blurrypiano/littleVulkanEngine/tree/master

+ 更好的粒子系统(搞不明白),更好的粒子系统tick逻辑

+ 使用贝塞尔曲线实现数字组件(现在也挺好看的?)

+ 重新加入摄像机,以便看到Z轴

+ 封装各个类的成员变量(不想动,不好调试)

+ 求出多面体的凸包,而不是严格限制顶点顺序(不想写)

+ 白框(即空矩形)需按边顺序放点
Expand Down
Binary file modified image/Rectangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified image/ThreadPool.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion src/core/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
namespace crp {
static constexpr float QUEUE_LAYER = 0.1;
static constexpr float PARTICLE_LAYER = 0.2;
static constexpr float NUMBER_LAYER = 0.2;
static constexpr float TASK_LAYER = 0.3;
static constexpr float THREAD_LAYER = 0.4;
constexpr int TASK_NUM = 8;
constexpr int THREAD_NUM = 5;
constexpr glm::vec3 SCALE{1.f, 1.f, 1.f};
constexpr float FRAME_TIME = 60.f;
constexpr float EPS = 1e-2;
constexpr float EPS = 1e-7;
constexpr float STRICT_EPS = 1e-7;
constexpr glm::vec3 TASK_COLOR = {0, .5f, .5f};
constexpr glm::vec3 THREAD_COLOR = {0, 0, .5f};
Expand All @@ -24,6 +25,15 @@ namespace crp {
return fabs(vec3a[0] - vec3b[0]) < EPS && fabs(vec3a[1] - vec3b[1]) < EPS;
}

inline bool FIX_EQUAL(glm::vec3 &vec3a, const glm::vec3 &vec3b) noexcept {
if (fabs(vec3a[0] - vec3b[0]) < EPS && fabs(vec3a[1] - vec3b[1]) < EPS) {
vec3a[0] = vec3b[0];
vec3a[1] = vec3b[1];
return true;
}
return false;
}

inline bool STRICT_EQUAL(const glm::vec3 &vec3a, const glm::vec3 &vec3b) noexcept {
return fabs(vec3a[0] - vec3b[0]) < STRICT_EPS && fabs(vec3a[1] - vec3b[1]) < STRICT_EPS;
}
Expand Down
5 changes: 2 additions & 3 deletions src/function/controller/keyboard_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ namespace crp {
}

void KeyboardController::addTask(GLFWwindow *window) {
int time = 0;
if (glfwGetKey(window, keys.add1) == GLFW_PRESS)add[0] = true;
if (glfwGetKey(window, keys.add2) == GLFW_PRESS)add[1] = true;
if (glfwGetKey(window, keys.add3) == GLFW_PRESS)add[2] = true;
if (glfwGetKey(window, keys.add4) == GLFW_PRESS)add[3] = true;
if (glfwGetKey(window, keys.add5) == GLFW_PRESS)add[4] = true;

long long time = 0;
if (add[0] && glfwGetKey(window, keys.add1) == GLFW_RELEASE)time = 1, add[0] = false;
if (add[1] && glfwGetKey(window, keys.add2) == GLFW_RELEASE)time = 2, add[1] = false;
if (add[2] && glfwGetKey(window, keys.add3) == GLFW_RELEASE)time = 3, add[2] = false;
Expand All @@ -52,7 +52,6 @@ namespace crp {

if (glfwGetKey(window, keys.debug) == GLFW_PRESS)globalContext.debug = true;
if (time == 0)return;
globalContext.runTimeSystem->taskQueueSystem->add(
[time] { std::this_thread::sleep_for(std::chrono::seconds(time)); });
globalContext.runTimeSystem->taskQueueSystem->addSleepWork(time);
}
}
7 changes: 4 additions & 3 deletions src/function/framework/component/delete_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace crp {
return;
}
mesh->setDirty(true);
//将坐下的点复制一个出来变为五边形
//将左下的点复制一个出来变为五边形
if (time == 0) {
mesh->points.emplace_back(mesh->points.back());
}
Expand All @@ -24,9 +24,10 @@ namespace crp {
auto direction = mesh->points[4] - mesh->points[3];
auto now = mesh->points[3];
//使得将粒子数量翻倍,使得粒子更为稠密以达到抗锯齿的效果
for (int i = 0; i <= 2 * time; i++) {
const int count = time * 2;
for (int i = 0; i <= count; i++) {
particleCom->addParticleEmitter(now);
now += direction / static_cast<float>(2 * time);
now += direction / static_cast<float>(count);
}
float halfTime = static_cast<float>(MAX_TIME) / 2;
if (time < MAX_TIME / 2) {
Expand Down
1 change: 1 addition & 0 deletions src/function/framework/component/delete_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "component.hpp"
#include "core/macro.hpp"
#include "number_component.hpp"

namespace crp {
class DeleteComponent : public Component {
Expand Down
47 changes: 6 additions & 41 deletions src/function/framework/component/mesh_component.cpp
Original file line number Diff line number Diff line change
@@ -1,48 +1,13 @@
#include "mesh_component.hpp"
#include "transform_component.hpp"
#include "function/framework/game_object.hpp"
#include "utils/geometry.hpp"

namespace crp {
std::vector<Vertex>
fillMesh(const std::vector<glm::vec3> &points, const glm::vec3 &color) {
std::vector<Vertex> vertices;
for (auto point: points) {
vertices.emplace_back(point, color);
}
return vertices;
}

std::vector<Vertex>
unfilledMesh(std::vector<glm::vec3> &points, const glm::vec3 &color) {
const float offset = 0.0025f;
std::vector<Vertex> vertices;

for (int i = 0; i + 1 < points.size(); ++i) {
//向线的法向方向平移从而画出带厚度的线
auto tt = points[i + 1] - points[i];
tt = {-tt.y, tt.x, tt.z};
glm::vec3 off = offset * glm::normalize(tt);
auto tmp = std::move(fillMesh(
{
points[i] - off, points[i] + off, points[i + 1] - off, points[i + 1] + off
}, color));
vertices.insert(vertices.end(), tmp.begin(), tmp.end());
}

auto tt = points.back() - points[0];
tt = {-tt.y, tt.x, tt.z};
glm::vec3 off = offset * glm::normalize(tt);
auto tmp = std::move(fillMesh(
{
points.back() - off, points.back() + off, points[0] - off, points[0] + off
}, color));
vertices.insert(vertices.end(), tmp.begin(), tmp.end());
return vertices;
}

MeshComponent::MeshComponent(const std::weak_ptr<GameObject> &parent,const std::string &type, std::vector<glm::vec3> &_points,
MeshComponent::MeshComponent(const std::weak_ptr<GameObject> &parent, const std::string &type,
std::vector<glm::vec3> &_points,
glm::vec3 &_color, bool _fill)
: Component(parent,type), points{_points}, color{_color}, fill{_fill} {
: Component(parent, type), points{_points}, color{_color}, fill{_fill} {
getWorld();
}

Expand All @@ -52,9 +17,9 @@ namespace crp {

void MeshComponent::getWorld() {
if (fill) {
vertexPoints = std::move(fillMesh(points, color));
vertexPoints = std::move(Geometry::fillMesh(points, color));
} else {
vertexPoints = std::move(unfilledMesh(points, color));
vertexPoints = std::move(Geometry::unfilledMesh(points, color));
}
getIndices();
}
Expand Down
10 changes: 5 additions & 5 deletions src/function/framework/component/move_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ namespace crp {
void MoveComponent::tick() {
if (isFinished())return;
MoveToPoint(destinations[now]);
if (EQUAL(center, destinations[now])) {
center = destinations[now];
if (FIX_EQUAL(center, destinations[now])) {
++now;
if (isFinished())return;
auto dir = destinations[now] - destinations[now - 1];
Expand All @@ -25,9 +24,7 @@ namespace crp {
int flag, pos, flag2;
if (fabs(center[0] - destination[0]) < EPS)flag = center[1] - destination[1] > 0 ? 1 : -1, pos = 1;
else flag = center[0] - destination[0] > 0 ? 1 : -1, pos = 0;
if (EQUAL(center, destination)) {
center[0] = destination[0];
center[1] = destination[1];
if (FIX_EQUAL(center, destination)) {
return;
}
center += direction;
Expand All @@ -36,6 +33,9 @@ namespace crp {
center[0] = destination[0];
center[1] = destination[1];
}
if (FIX_EQUAL(center, destination)) {
return;
}
}

void MoveComponent::setDestination(glm::vec3 &_destination, float _time) {
Expand Down
3 changes: 1 addition & 2 deletions src/function/framework/component/move_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ namespace crp {
destinations.clear();
return true;
}
if (EQUAL(center, destinations[now])) {
center = destinations[now];
if (FIX_EQUAL(center, destinations[now])) {
now = 0;
destinations.clear();
}
Expand Down
58 changes: 58 additions & 0 deletions src/function/framework/component/number_component.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "number_component.hpp"
#include "utils/number.hpp"
#include "function/framework/game_object.hpp"
#include "mesh_component.hpp"
#include "function/global/global_context.hpp"

namespace crp {
void NumberComponent::tick() {
if (!number)return;
if (!model)return;
if (isDirty())return;
if (begin) {
using namespace std::chrono;
if (fistTick)//任务执行时第一次计时
lastTime = steady_clock::now();
fistTick = false;
auto nowTime = steady_clock::now();
duration<float> timeSpan = duration_cast<duration<float>>(nowTime - lastTime);
deltaTime += timeSpan.count();
if (deltaTime > 1) {
setNumber(number - 1);
deltaTime -= 1;
} else
setNumber(number);
lastTime = nowTime;
}
auto transform = m_parent_object.lock()->tryGetComponent(TransformComponent);
PushConstantData push{};
push.modelMatrix = transform->mat4();
push.normalMatrix = transform->normalMatrix();
push.modelMatrix[3][2] = 0;
globalContext.simpleRenderPass->bind(push, model);
}

void NumberComponent::setNumber(int num) {
number = num;
if (number == 0)return;
auto vertices = std::move(Number::getNumber(width, height,
glm::vec3{1., 0.8, 0.4} * (static_cast<float>(number) - deltaTime) /
5.f, number));
std::vector<uint32_t> indices;
for (int i = 0; i < vertices.size(); i += 4) {
for (int j = i; j < i + 2; j++) {
for (int k = 0; k < 3; ++k) {
indices.emplace_back(j + k);
}
}
}
model = std::make_shared<Model>(vertices, indices);
}

NumberComponent::NumberComponent(const std::weak_ptr<GameObject> &parent, const std::string &type, float meshWidth,
float meshHeight, int num) :
Component(parent, type), width{meshWidth}, height{meshHeight}, number{num}, begin{false} {

setNumber(number);
}
}
29 changes: 29 additions & 0 deletions src/function/framework/component/number_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "component.hpp"
#include "utils/number.hpp"
#include "render/render_model.hpp"

namespace crp {
class NumberComponent : public Component {
public:
explicit NumberComponent(const std::weak_ptr<GameObject> &parent, const std::string &type,
float meshWidth = 0, float meshHeight = 0, int num = 5);

void tick() override;

void setBegin() { begin = true; }

private:
void setNumber(int number);

std::shared_ptr<Model> model{};
float width;
float height;
int number;
float deltaTime;
std::chrono::steady_clock::time_point lastTime;
std::atomic<bool> fistTick{true};
std::atomic<bool> begin;
};
}
Loading

0 comments on commit 400794d

Please sign in to comment.