Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
tick_counter.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 #include <iomanip>
5 #include <random>
6 #include <thread>
7 
8 #include "../../render_stack.h"
10 #include "components/3rdparty/imgui/imgui.h"
13 #include <Strings/components/utils/converters/converters.h>
14 
16 {
25  {
26  private:
27  BitmapText* tick_display;
28  BitmapText* tick_display_2;
29  int counter = 0;
30 
31  std::thread incremeneter_thread;
32  bool stop_thread = false;
33  bool thread_stopped = false;
34 
35  public:
36  void increment()
37  {
38  while (!stop_thread)
39  {
40  counter++;
41  }
42 
43  thread_stopped = true;
44  }
45 
47  {
49 
50  x = 50;
51  y = 820;
52 
53  {
54  tick_display = new BitmapText();
55 
56  tick_display->font_id = Blam::Config::GetConfig()->GetString("ui_default_font");
57  tick_display->use_shadow = true;
58  tick_display->color = D2D1::ColorF(1, 1, 1, 1);
59 
60  tick_display->SetTranslation(x, y);
61  }
62 
63 
64  {
65  tick_display_2 = new BitmapText();
66 
67  tick_display_2->font_id = Blam::Config::GetConfig()->GetString("ui_default_font");
68  tick_display_2->use_shadow = true;
69  tick_display_2->color = D2D1::ColorF(1, 1, 1, 1);
70 
71  tick_display_2->SetTranslation(x, y + 15);
72  }
73 
75 
77 
78  incremeneter_thread = std::thread(&BlamRendering::RenderStack::TickCounter::increment, this);
79  incremeneter_thread.detach();
80  }
81 
83  {
84  stop_thread = true;
85 
86  while (!thread_stopped)
87  {
88  // Wait for thread to finish
89  }
90 
91  delete tick_display;
92  delete this;
93  }
94 
95  void Draw()
96  {
97  tick_display->SetTranslation(x, y);
98  tick_display_2->SetTranslation(x, y + 15);
99 
100 
101  tick_display->visible = visible;
102 
103  if (visible)
104  {
105  std::string new_text = BlamStrings::Converters::BytesToString((void*)counter, sizeof(counter));
106 
107  if (new_text.length() < 8)
108  {
109  while (new_text.length() != 8)
110  {
111  new_text.insert(new_text.begin(), '0');
112  }
113  }
114 
115  tick_display->text = new_text;
116  tick_display_2->text = new_text;
117  }
118 
119  tick_display->Draw();
120  tick_display_2->Draw();
121  }
122 
124  {
125 
126  }
127 
128  void OnTickEvent(TickEvent* event)
129  {
130  counter++;
131  }
132  };
133 }
Blam::Events::RegisterListener
BLAM void RegisterListener(BlamEventListener *listener)
Registers a an event listener.
Definition: events.cpp:75
BlamRendering::RenderStack::StackObjectBase::visible
bool visible
Whether or not the object is visible.
Definition: render_stack.h:375
BlamRendering::RenderStack::BitmapText::font_id
std::string font_id
The ID of the font.
Definition: render_stack.h:844
BitmapText
@ BitmapText
Bitmap-based text, uses Blamite font system.
Definition: render_stack.h:72
BlamRendering::RenderStack::StackObjectBase::type_label
StackType type_label
The type of the object.
Definition: render_stack.h:372
Blam::Config::GetConfig
BLAM ConfigFile * GetConfig()
Definition: compat.cpp:5
BlamRendering::RenderStack
Namespace containing things relating to the Render Stack.
Definition: drawing.h:14
BlamRendering::RenderStack::TickCounter
Class to contain the onscreen tick counter display.
Definition: tick_counter.hpp:24
BlamRendering::RenderStack::TickCounter::OnTickEvent
void OnTickEvent(TickEvent *event)
Called when the listener is subscribed to Key Press events, and a new TickEvent is fired.
Definition: tick_counter.hpp:128
events.h
BlamRendering::RenderStack::BitmapText::text
std::string text
The text to display.
Definition: render_stack.h:846
BlamRendering::RenderStack::StackObjectBase::color
D2D1_COLOR_F color
The color of the object.
Definition: render_stack.h:370
TickEvent
Class representing an engine tick event.
Definition: TickEvent.h:10
BlamRendering::RenderStack::StackObjectBase::y
float y
The Y coordinate of the object.
Definition: render_stack.h:378
STACKTYPE_STATS
#define STACKTYPE_STATS
Definition: render_stack.h:27
BlamRendering::RenderStack::TickCounter::ShowImPropertyEditor
void ShowImPropertyEditor()
Shows a set of ImGUI properties associated with the object.
Definition: tick_counter.hpp:123
BlamRendering::RenderStack::BitmapText::Draw
void Draw()
Draws the stack object.
Definition: BitmapText.cpp:13
BlamRendering::RenderStack::TickCounter::increment
void increment()
Definition: tick_counter.hpp:36
BlamRendering::RenderStack::BitmapText::use_shadow
bool use_shadow
Whether or not to draw the text with a drop shadow.
Definition: render_stack.h:852
BlamRendering::RenderStack::StackObjectBase::SetTranslation
void SetTranslation(float new_x, float new_y)
Sets the translation of the object.
Definition: StackObjectBase.cpp:55
BlamRendering::RenderStack::TickCounter::~TickCounter
~TickCounter()
Definition: tick_counter.hpp:82
BlamEventListener::Subscribe
void Subscribe(BlamEventType type)
Subscribes to an event type.
Definition: BlamEventListener.cpp:3
EventType_Tick
@ EventType_Tick
Definition: BlamEvent.h:9
TickEvent.h
Blam::Config::ConfigFile::GetString
std::string GetString(std::string option)
Definition: compat.cpp:58
config.h
BlamRendering::RenderStack::BitmapText
Class representing text drawn using a Bitmap-based engine font.
Definition: render_stack.h:794
BlamRendering::RenderStack::StackObjectBase
Base class for all render stack objects.
Definition: render_stack.h:194
BlamEventListener
Class representing an Event Listener.
Definition: events.h:27
BlamRendering::RenderStack::TickCounter::Draw
void Draw()
Draws the stack object.
Definition: tick_counter.hpp:95
BlamRendering::RenderStack::TickCounter::TickCounter
TickCounter()
Definition: tick_counter.hpp:46
BlamRendering::RenderStack::StackObjectBase::x
float x
The X coordinate of the object.
Definition: render_stack.h:377