|
|
@@ -18,7 +18,7 @@ using namespace engine;
|
|
|
|
|
|
static graphics::object create() {
|
|
|
Json::Value value;
|
|
|
- value["material"]["texture"]["file"] = "data/images/rock.png";
|
|
|
+ value["material"]["texture"]["file"] = "data/images/font.bmp";
|
|
|
value["material"]["texture"]["uniform"] = "u_normalMap";
|
|
|
return engine::to_object(value);
|
|
|
}
|
|
|
@@ -31,32 +31,46 @@ static std::size_t digits(env::clock::duration const & fpscap) {
|
|
|
return digits;
|
|
|
}
|
|
|
|
|
|
+std::unordered_map<char, math::vec2> const indices{
|
|
|
+ {'.', make_vector(6.f, 6.f)}, {'0', make_vector(0.f, 5.f)},
|
|
|
+ {'1', make_vector(1.f, 5.f)}, {'2', make_vector(2.f, 5.f)},
|
|
|
+ {'3', make_vector(3.f, 5.f)}, {'4', make_vector(4.f, 5.f)},
|
|
|
+ {'5', make_vector(5.f, 5.f)}, {'6', make_vector(6.f, 5.f)},
|
|
|
+ {'7', make_vector(7.f, 5.f)}, {'8', make_vector(0.f, 4.f)},
|
|
|
+ {'9', make_vector(1.f, 4.f)}};
|
|
|
+
|
|
|
+math::vec2 index(char value) {
|
|
|
+ auto it = indices.find(value);
|
|
|
+ return it != indices.end() ? it->second : make_vector(0.f, 0.f);
|
|
|
+}
|
|
|
+
|
|
|
+math::vec2 number_index(int num) { return index(char(num + '0')); }
|
|
|
+
|
|
|
fps_counter::fps_counter(env::clock::duration const & fpscap,
|
|
|
std::size_t precision)
|
|
|
: digits_(precision), magnitude_(std::pow(10, digits_)),
|
|
|
glyphs_(digits(fpscap) + digits_ + 1, create()) {
|
|
|
- auto offset = make_vector(0.f, 44.f);
|
|
|
- auto pixels = make_vector(12.f, 16.f);
|
|
|
- auto bounds = make_vector(512.f, 64.f);
|
|
|
- auto glyph_size = pixels / bounds;
|
|
|
+ auto pixels = make_vector(0.125f, 0.125f);
|
|
|
for (std::size_t i = 0; i < glyphs_.size(); ++i) {
|
|
|
- glyphs_[i].location.origin = make_vector((i + 1) * 10.f, 10.f);
|
|
|
- glyphs_[i].location.size = make_vector(10.f, 10.f);
|
|
|
+ glyphs_[i].location.origin =
|
|
|
+ make_vector((glyphs_.size() - i) * 10.f - 5.f, 680.f);
|
|
|
+ glyphs_[i].location.size = make_vector(20.f, 20.f);
|
|
|
glyphs_[i].points = glyphs_[i].location;
|
|
|
- glyphs_[i].frame.size = glyph_size;
|
|
|
+ glyphs_[i].frame.size = pixels;
|
|
|
}
|
|
|
- glyphs_[digits_].frame.origin = (offset + 10 * pixels) / bounds;
|
|
|
+ glyphs_[digits_].frame.origin = index('.') * pixels;
|
|
|
}
|
|
|
|
|
|
fps_counter::~fps_counter() {}
|
|
|
|
|
|
void fps_counter::set_frame_step(env::clock::duration const & since) {
|
|
|
- auto offset = make_vector(0.f, 48.f);
|
|
|
- auto pixels = make_vector(12.f, 16.f);
|
|
|
- auto bounds = make_vector(512.f, 64.f);
|
|
|
+ if (++counter_ != change_after_) { return; }
|
|
|
+ counter_ = 0;
|
|
|
+ auto pixels = make_vector(0.125f, 0.125f);
|
|
|
auto fps = magnitude_ * env::clock::duration::period::den / since.count();
|
|
|
- for (std::size_t i = 0; i < glyphs_.size(); ++i, fps /= 10) {
|
|
|
+ for (std::size_t i = 0; i < glyphs_.size(); ++i) {
|
|
|
if (i == digits_) continue;
|
|
|
- glyphs_[i].frame.origin = (offset + (fps % 10) * pixels) / bounds;
|
|
|
+ glyphs_[i].frame.origin = number_index(fps % 10) * pixels;
|
|
|
+ fps /= 10;
|
|
|
}
|
|
|
}
|