Rolling average framerate display

This commit is contained in:
2024-10-04 14:46:20 -04:00
parent e5e1faeb88
commit e8ca20ad0c
4 changed files with 64 additions and 42 deletions

View File

@@ -25,7 +25,7 @@ CPMAddPackage(
CPMAddPackage(
NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-19.zip
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-20.zip
)
CPMAddPackage(

View File

@@ -3,8 +3,8 @@
#pragma once
#include <Client/Scene.hpp>
#include <JGL/types/Texture.h>
#include <JGL/types/Font.h>
#include <JGL/JGL.h>
#include <array>
namespace CaveGame::Client
{
@@ -31,11 +31,17 @@ namespace CaveGame::Client
Vector2 window_size;
float increment = 0;
std::array<JGL::RenderTarget*, 16> column_textures{};
int column_width = 0;
std::vector<float> scroll_offsets;
std::vector<std::vector<char>> matrix;
void ComputeMatrix();
void ComputeMatrixGlyphTable();
void ComputeMatrixTextureCache();
void DrawMatrix();
void DrawProgressBar();
};
}

View File

@@ -1,17 +1,29 @@
#include <Client/Splash.hpp>
#include <JGL/JGL.h>
JGL::RenderTarget* matrix_render_target = nullptr;
CaveGame::Client::Splash::Splash() : Scene()
{
font = JGL::Font();
ComputeMatrixGlyphTable();
}
void CaveGame::Client::Splash::ComputeMatrixGlyphTable()
{
J3ML::Algorithm::RNG rng;
for (int i = 0; i < 100; i++)
{
for (int i = 0; i < 128; i++)
scroll_offsets.push_back(rng.Float(0, 300.5));
for (int i = 0; i < column_textures.size(); i++)
{
matrix.push_back(std::vector<char>());
for (int j = 0; j < 100; j++)
{
@@ -24,32 +36,27 @@ CaveGame::Client::Splash::Splash() : Scene()
}
void CaveGame::Client::Splash::ComputeMatrix()
void CaveGame::Client::Splash::ComputeMatrixTextureCache()
{
if (matrix_render_target == nullptr) {
auto zero = font.MeasureString("0", 16);
matrix_render_target = new JGL::RenderTarget({zero.x, zero.y * 100}, {0, 0, 0, 0}, false);
Color4 text_col = Color4(32, 192, 92, 255);
JGL::J2D::Begin(matrix_render_target, true);
auto glyph_measurement = font.MeasureString("0", 16);
column_width = glyph_measurement.x;
for (int col = 0; col < 100; col++)
JGL::J2D::DrawString(text_col, std::to_string(rand() % 2), 0, zero.y * col, 1, 16, font);
for (int i = 0; i < column_textures.size(); i++)
{
Vector2 column_size = {glyph_measurement.x, glyph_measurement.y * 100};
auto* column = new JGL::RenderTarget(column_size, {0, 0, 0, 0}, false);
JGL::J2D::Begin(column, true);
for (int col = 0; col < 50; col++) {
Color4 text_col = Color4(32, 192, 92, 255 - (col*4));
JGL::J2D::DrawString(text_col, std::to_string(rand() % 2), 0, glyph_measurement.y * col, 1, 16, font);
}
JGL::J2D::End();
column_textures[i] = column;
}
/*
for (int col = 0; col < 100; col++)
{
float scroll = (scroll_offsets[col] * load_percent);
for (int row = 0; row < 80; row++)
{
char elem = matrix[col][row];
Color4 text_col = Color4(32, 192, 92, 255 - (row*5));
JGL::J2D::DrawString(text_col, std::string(1, elem), (col*16), (row*16) + scroll, 1, 16, font);
}
}
*/
}
@@ -71,6 +78,19 @@ void CaveGame::Client::Splash::DrawProgressBar()
JGL::J2D::FillRect(Colors::White, bar_pos, {progress_bar_length, bar_height});
}
void CaveGame::Client::Splash::DrawMatrix()
{
for (int i = 0; i < window_size.x/column_width; i++)
{
float scroll = (scroll_offsets[i] * load_percent);
auto column = column_textures[i%column_width];
JGL::J2D::DrawRenderTargetAsSprite(*column, {static_cast<float>(i*16),scroll});
}
}
void CaveGame::Client::Splash::Draw()
{
@@ -87,10 +107,9 @@ void CaveGame::Client::Splash::Draw()
// TODO: Implement draw-point offset to maintain sensible aspect ratio on the image.
ComputeMatrix();
JGL::J2D::Begin();
JGL::J2D::DrawRenderTargetAsSprite(*matrix_render_target, {0,0});
DrawMatrix();
//
JGL::J2D::DrawSprite(splash, {0, 0}, 0.f, {0, 0}, aspect);
DrawProgressBar();
@@ -113,11 +132,15 @@ void CaveGame::Client::Splash::Update(float elapsed)
void CaveGame::Client::Splash::Load() {
splash = JGL::Texture("assets/redacted.png");
ComputeMatrixTextureCache();
Scene::Load();
}
void CaveGame::Client::Splash::Unload() {
Scene::Unload();
}
void CaveGame::Client::Splash::PassFont(JGL::Font passed) {

View File

@@ -45,6 +45,7 @@ namespace CaveGame::ClientApp
bool render_grid = true;
bool generate_grid = true;
float our_avg = 0.f;
CaveGameWindow(const std::string& title, int width, int height) : ReWindow::RWindow(title, width, height) {
@@ -151,8 +152,7 @@ namespace CaveGame::ClientApp
}
void update(float elapsed)
{
void update(float elapsed) {
if (splash_ctx->SplashComplete())
ChangeScene(new CaveGame::Client::MainMenu());
@@ -164,12 +164,6 @@ namespace CaveGame::ClientApp
// Ugly temporary hack.
splash_ctx->PassWindowSize(getSize());
//
if (elapsed < 1.f/999.f)
{
std::this_thread::sleep_for(1ms);
}
}
void display()
@@ -190,9 +184,8 @@ namespace CaveGame::ClientApp
std::format("frame: {}", refresh_count),
std::format("delta: {}ms", J3ML::Math::Round(delta_time*1000)),
std::format("fps: {}", J3ML::Math::Round(refresh_rate)),
std::format("avg: {}", J3ML::Math::Round(avg_refresh_rate))
});
}
void procgen()