-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
754 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
Oops, something went wrong.