Skip to content

Commit

Permalink
updated default font and added minor changes to the binary blobs setup
Browse files Browse the repository at this point in the history
  • Loading branch information
PaoloMazzon committed Nov 17, 2023
1 parent 877f019 commit 213a8b9
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 1,131 deletions.
2 changes: 1 addition & 1 deletion examples/testing/Astro.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[engine]
enableTypeChecking=True
enableDebugOverlay=False
enableDebugOverlay=True
enableAssetsPrint=True
2 changes: 1 addition & 1 deletion examples/testing/data/game/Game.wren
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Game is Level {
update() {
super.update()

Renderer.draw_font(null, Engine.fps.toString, 0, 0)
//Renderer.draw_font(null, Engine.fps.toString, 0, 0)
}

destroy() {
Expand Down
Binary file added font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion generate_wren_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ def add_file_string(fname, var_type, var_suffix):
string += add_file_string("prog/lib/Util.wren", "const char", "_WREN_SOURCE")
string += add_file_string("prog/lib/Tiled.wren", "const char", "_WREN_SOURCE")
string += add_file_string("loading.png", "const unsigned char", "_SCREEN_PNG")
with open("src/BinaryBlobs.h", "w") as f:
with open("src/WrenHeaders.h", "w") as f:
f.write(string)

string = """/// \\file Blobs.h
/// \\author Paolo Mazzon
/// \\brief Automatically generated file from generate_wren_blobs.py
#pragma once
#include <stdint.h>
"""
string += add_file_string("distro.png", "const uint8_t", "_PNG")
string += add_file_string("font.png", "const uint8_t", "_PNG")
with open("src/Blobs.h", "w") as f:
f.write(string)

1,321 changes: 208 additions & 1,113 deletions src/Blobs.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/RendererBindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static void _vksk_DrawTexture(WrenVM *vm, VK2DTexture tex, float x, float y, flo

void _vksk_RendererBindingsInit(void *textureData, int size) {
gDefaultFontTexture = vk2dTextureFrom(textureData, size);
gDefaultFont = juFontLoadFromTexture(gDefaultFontTexture, 32, 128, 16, 32);
gDefaultFont = juFontLoadFromTexture(gDefaultFontTexture, 32, 128, 7 * 3, 8 * 3);
}

void _vksk_RendererBindingsQuit() {
Expand Down
26 changes: 13 additions & 13 deletions src/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ static void _vksk_SetWindowIcon(WrenVM *vm) {

static void _vksk_InitializeDebug() {
int x, y, channels;
uint8_t *pixels = stbi_load_from_memory(DEBUG_FONT_PNG, sizeof(DEBUG_FONT_PNG), &x, &y, &channels, 4);
uint8_t *pixels = stbi_load_from_memory(FONT_PNG, sizeof(FONT_PNG), &x, &y, &channels, 4);
gDebugFontImage = vk2dImageFromPixels(vk2dRendererGetDevice(), pixels, x, y, true);
gDebugFont = vk2dTextureLoadFromImage(gDebugFontImage);
stbi_image_free(pixels);
pixels = stbi_load_from_memory(DEBUG_DISTRITUBTION_GRAPH_PNG, sizeof(DEBUG_DISTRITUBTION_GRAPH_PNG), &x, &y, &channels, 4);
pixels = stbi_load_from_memory(DISTRO_PNG, sizeof(DISTRO_PNG), &x, &y, &channels, 4);
gDebugGraphImage = vk2dImageFromPixels(vk2dRendererGetDevice(), pixels, x, y, true);
gDebugGraph = vk2dTextureLoadFromImage(gDebugGraphImage);
stbi_image_free(pixels);
Expand All @@ -96,26 +96,26 @@ static void _vksk_DebugPrint(float x, float y, const char *fmt, ...) {
int index = buffer[i] - 32;

if (index >= 0 && index < 96) {
float drawX = roundf((index * 16) % 256);
float drawY = roundf(32 * floorf((index * 16) / (256)));
vk2dDrawTexturePart(gDebugFont, x, y, drawX, drawY, 16, 32);
x += 16;
float drawX = roundf((index * 21) % 336);
float drawY = roundf(24 * floorf((index * 21) / (336)));
vk2dDrawTexturePart(gDebugFont, x, y, drawX, drawY, 21, 24);
x += 21;
}
}
}
}

static void _vksk_DrawDebugOverlay() {
vk2dRendererLockCameras(VK2D_DEFAULT_CAMERA);
_vksk_DebugPrint(2, 0, "FPS: %0.2f", gFPS);
_vksk_DebugPrint(2, 34, "Entities: %i", gEntityCount);
_vksk_DebugPrint(0, 0, "FPS: %0.2f", gFPS);
_vksk_DebugPrint(0, 26, "Entities: %i", gEntityCount);
if (gTimeStep != 0) {
_vksk_DebugPrint(2, 34 + 34, "Time Step: %0.2ffps | TS%: %0.2f% | ", gAverageTimeStep, gTimeStepPercentProc);
float x = 35 * 16;
_vksk_DebugPrint(0, 26 + 26, "TS:%0.2ffps TS%:%0.2f%", gAverageTimeStep, gTimeStepPercentProc);
float x = 21 * 21;
float lx = x + (128 * gAverageTimeStepDistribution);
vk2dDrawTexture(gDebugGraph, x, 34 + 34);
vk2dDrawTexture(gDebugGraph, x, 26 + 26);
vk2dRendererSetColourMod(VK2D_BLACK);
vk2dDrawRectangle(lx - 1, 34 + 34, 2, 32);
vk2dDrawRectangle(lx - 1, 26 + 26, 2, 32);
vk2dRendererSetColourMod(VK2D_DEFAULT_COLOUR_MOD);
}
vk2dRendererUnlockCameras();
Expand Down Expand Up @@ -266,7 +266,7 @@ void vksk_Start() {
juInit(gWindow, 0, 0);

// Internal stuff
_vksk_RendererBindingsInit((void*)DEBUG_FONT_PNG, sizeof(DEBUG_FONT_PNG)); // basically just to create the default font
_vksk_RendererBindingsInit((void*)FONT_PNG, sizeof(FONT_PNG)); // basically just to create the default font
_vksk_SetWindowIcon(vm);
_vksk_InitializeDebug();
_vksk_RuntimeControllerRefresh();
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/WrenPreprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdlib.h>

#include "src/WrenPreprocessor.h"
#include "src/BinaryBlobs.h"
#include "src/WrenHeaders.h"
#include "src/Packer.h"
#include "src/Runtime.h"

Expand Down

0 comments on commit 213a8b9

Please sign in to comment.