Peoplemon  0.1.0
Peoplemon 3 game source documentation
TrainerIntro.cpp
Go to the documentation of this file.
1 #include "TrainerIntro.hpp"
2 
3 #include <BLIB/Render.hpp>
4 #include <Core/Properties.hpp>
5 
6 namespace game
7 {
8 namespace state
9 {
10 namespace intros
11 {
12 namespace
13 {
14 constexpr float IntroLength = 1.6f;
15 bool pipelineCreated = false;
16 
17 struct FragmentUniform {
18  glm::vec2 windowSize;
19  float progress; // [0, 1]
20 };
21 
22 using Bindings = bl::rc::ds::Bindings<bl::rc::ds::GlobalUniformBuffer<FragmentUniform>>;
23 using Factory = bl::rc::ds::GenericDescriptorSetFactory<Bindings, VK_SHADER_STAGE_FRAGMENT_BIT>;
24 using Instance = bl::rc::ds::GenericDescriptorSetInstance<Bindings>;
25 
26 } // namespace
27 
29 : time(0.f) {}
30 
31 void TrainerSequence::start(bl::engine::Engine& engine) {
32  if (!pipelineCreated) {
33  pipelineCreated = true;
34 
35  bl::rc::vk::PipelineParameters params;
36  params.withSimpleDepthStencil(false)
37  .withPrimitiveType(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
38  .addDescriptorSet<bl::rc::ds::Scene2DFactory>()
39  .addDescriptorSet<bl::rc::ds::Object2DFactory>()
40  .addDescriptorSet<Factory>()
41  .withShaders(bl::rc::Config::ShaderIds::Vertex2D,
42  "Resources/Shaders/Battle/trainerIntro.frag.spv");
43  engine.renderer().pipelineCache().createPipline(core::Properties::TrainerIntroPipelineId,
44  params.build());
45  }
46 
47  // TODO - play sound and start music
48 
49  auto overlay = engine.renderer().getObserver().getOrCreateSceneOverlay();
50  e = &engine;
51  time = 0.f;
52  const sf::Vector2f screenCenter = core::Properties::WindowSize() * 0.5f;
53 
54  background.create(engine, {core::Properties::WindowSize().x, core::Properties::WindowSize().y});
55  background.setFillColor(sf::Color::Black);
56  background.addToSceneWithCustomPipeline(
57  overlay, bl::rc::UpdateSpeed::Static, core::Properties::TrainerIntroPipelineId);
58 
59  ballTxtr = engine.renderer().texturePool().getOrLoadTexture(
60  bl::util::FileUtil::joinPath(core::Properties::ImagePath(), "Battle/battleBall.png"));
61  ball.create(engine, ballTxtr);
62  ball.getTransform().setOrigin(ballTxtr->size() * 0.5f);
63  ball.getTransform().setPosition({screenCenter.x, screenCenter.y});
64  ball.getTransform().setScale(0.f, 0.f);
65  ball.setParent(background);
66  ball.addToScene(overlay, bl::rc::UpdateSpeed::Dynamic);
67 
68  Instance& set = overlay->getDescriptorSet<Instance>();
69  uniform = &set.getBindingPayload<FragmentUniform>();
70 }
71 
72 void TrainerSequence::update(float dt) {
73  time += dt;
74 
75  FragmentUniform* u = static_cast<FragmentUniform*>(uniform);
76  const sf::Vector2u ws = e->window().getSfWindow().getSize();
77  u->progress = time / IntroLength;
78  u->windowSize.x = static_cast<float>(ws.x);
79  u->windowSize.y = static_cast<float>(ws.y);
80 
81  ball.getTransform().setScale(u->progress);
82 }
83 
84 bool TrainerSequence::finished() const { return time >= IntroLength; }
85 
86 } // namespace intros
87 } // namespace state
88 } // namespace game
float progress
glm::vec2 windowSize
Parent namespace for all functionality unique to the game.
static sf::Vector2f WindowSize()
Definition: Properties.cpp:262
static constexpr std::uint32_t TrainerIntroPipelineId
Definition: Properties.hpp:141
static const std::string & ImagePath()
Definition: Properties.cpp:333
virtual void update(float dt) override
virtual bool finished() const override
virtual void start(bl::engine::Engine &engine) override