Peoplemon  0.1.0
Peoplemon 3 game source documentation
WildIntro.cpp
Go to the documentation of this file.
1 #include "WildIntro.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 constexpr std::array<glm::vec4, 6> BarColors = {glm::vec4(235.f, 64.f, 52.f, 255.f) / 255.f,
17  glm::vec4(38.f, 168.f, 34.f, 255.f) / 255.f,
18  glm::vec4(240.f, 185.f, 77.f, 255.f) / 255.f,
19  glm::vec4(39.f, 86.f, 217.f, 255.f) / 255.f,
20  glm::vec4(219.f, 219.f, 9.f, 255.f) / 255.f,
21  glm::vec4(219.f, 9.f, 202.f, 255.f) / 255.f};
22 
23 struct FragmentUniform {
24  glm::vec2 windowSize;
25  float progress;
26  std::uint32_t base;
27  std::array<glm::vec4, 6> colors;
28 };
29 
30 using Bindings = bl::rc::ds::Bindings<bl::rc::ds::GlobalUniformBuffer<FragmentUniform>>;
31 using Factory = bl::rc::ds::GenericDescriptorSetFactory<Bindings, VK_SHADER_STAGE_FRAGMENT_BIT>;
32 using Instance = bl::rc::ds::GenericDescriptorSetInstance<Bindings>;
33 
34 } // namespace
35 
37 : time(0.f)
38 , shuffleTime(0.f) {}
39 
40 void WildSequence::start(bl::engine::Engine& engine) {
41  // TODO - play sound and start music
42  time = 0.f;
43  shuffleTime = 0.f;
44 
45  if (!pipelineCreated) {
46  pipelineCreated = true;
47 
48  bl::rc::vk::PipelineParameters params;
49  params.withSimpleDepthStencil(false)
50  .withPrimitiveType(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
51  .addDescriptorSet<bl::rc::ds::Scene2DFactory>()
52  .addDescriptorSet<bl::rc::ds::Object2DFactory>()
53  .addDescriptorSet<Factory>()
54  .withShaders(bl::rc::Config::ShaderIds::Vertex2D,
55  "Resources/Shaders/Battle/wildIntro.frag.spv");
56  engine.renderer().pipelineCache().createPipline(core::Properties::WildIntroPipelineId,
57  params.build());
58  }
59 
60  auto overlay = engine.renderer().getObserver().getOrCreateSceneOverlay();
61  const sf::Vector2f screenCenter = core::Properties::WindowSize() * 0.5f;
62 
63  background.create(engine, {core::Properties::WindowSize().x, core::Properties::WindowSize().y});
64  background.addToSceneWithCustomPipeline(
65  overlay, bl::rc::UpdateSpeed::Static, core::Properties::WildIntroPipelineId);
66 
67  Instance& set = overlay->getDescriptorSet<Instance>();
68  FragmentUniform& uni = set.getBindingPayload<FragmentUniform>();
69  uni.base = 0;
70  uni.colors = BarColors;
71  uni.progress = 0.f;
72 
73  e = &engine;
74  uniform = &uni;
75 }
76 
77 void WildSequence::update(float dt) {
78  constexpr float ShuffleTime = 0.085f;
79 
80  time += dt;
81  shuffleTime += dt;
82 
83  FragmentUniform* u = static_cast<FragmentUniform*>(uniform);
84  const sf::Vector2u ws = e->window().getSfWindow().getSize();
85  u->progress = time / IntroLength;
86  u->windowSize.x = static_cast<float>(ws.x);
87  u->windowSize.y = static_cast<float>(ws.y);
88 
89  if (shuffleTime >= ShuffleTime) {
90  u->base = (u->base + 1) % BarColors.size();
91  shuffleTime = 0.f;
92  }
93 }
94 
95 bool WildSequence::finished() const { return time >= 2.5f; }
96 
97 } // namespace intros
98 } // namespace state
99 } // namespace game
std::uint32_t base
Definition: WildIntro.cpp:26
std::array< glm::vec4, 6 > colors
Definition: WildIntro.cpp:27
float progress
Definition: WildIntro.cpp:25
glm::vec2 windowSize
Definition: WildIntro.cpp:24
Parent namespace for all functionality unique to the game.
static sf::Vector2f WindowSize()
Definition: Properties.cpp:262
static constexpr std::uint32_t WildIntroPipelineId
Definition: Properties.hpp:142
virtual void start(bl::engine::Engine &engine) override
Definition: WildIntro.cpp:40
virtual void update(float dt) override
Definition: WildIntro.cpp:77
virtual bool finished() const override
Definition: WildIntro.cpp:95