weird text sizing?

This commit is contained in:
Vicente Ferrari Smith 2026-01-12 18:29:26 +01:00
parent 4b61aa5477
commit 494c3a3418
3 changed files with 74 additions and 7 deletions

View File

@ -104,6 +104,7 @@ pub fn build(b: *std.Build) void {
const raylib = raylib_dep.module("raylib"); // main raylib module const raylib = raylib_dep.module("raylib"); // main raylib module
const raygui = raylib_dep.module("raygui"); // raygui module const raygui = raylib_dep.module("raygui"); // raygui module
const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library
raylib_artifact.root_module.addCMacro("SUPPORT_CUSTOM_FRAME_CONTROL", "");
client.linkLibrary(raylib_artifact); client.linkLibrary(raylib_artifact);
client.root_module.addImport("raylib", raylib); client.root_module.addImport("raylib", raylib);

View File

@ -1,13 +1,21 @@
const std = @import("std"); const std = @import("std");
const zm = @import("zmath"); const zm = @import("zmath");
const znet = @import("znet"); const znet = @import("znet");
const rl = @import("raylib"); const rl = @import("raylib");
const bufzilla = @import("bufzilla"); const bufzilla = @import("bufzilla");
const shared = @import("shared"); const shared = @import("shared");
const client = @import("client.zig"); const client = @import("client.zig");
const entity = @import("entity.zig"); const entity = @import("entity.zig");
const misc = @import("misc.zig");
const dt : f32 = 1.0 / 200.0;
var t : f32 = 0;
var gt : f32 = 0;
var accumulator : f32 = 0;
var k : f32 = 1.0;
var frame : i32 = 0;
const screen_width = 640; const screen_width = 640;
const screen_height = 480; const screen_height = 480;
@ -94,7 +102,21 @@ pub fn main() !void {
// rl.playMusicStream(music); // rl.playMusicStream(music);
std.log.info("is music playing? {}", .{rl.isMusicStreamPlaying(music)}); std.log.info("is music playing? {}", .{rl.isMusicStreamPlaying(music)});
var old_time : f32 = @floatCast(rl.getTime());
while (!rl.windowShouldClose()) { // Detect window close button or ESC key while (!rl.windowShouldClose()) { // Detect window close button or ESC key
const new_time : f32 = @floatCast(rl.getTime());
var frame_time = new_time - old_time;
old_time = new_time;
if (frame_time > 0.25)
frame_time = 0.25;
t += frame_time;
accumulator += frame_time * k;
// std.log.info("t: {}", .{t});
while (try host.service(0)) |event| switch (event) { while (try host.service(0)) |event| switch (event) {
.connect => |data| { .connect => |data| {
_ = data; _ = data;
@ -109,8 +131,6 @@ pub fn main() !void {
const slice = data.packet.dataSlice(); const slice = data.packet.dataSlice();
std.log.info("{s}", .{slice});
var reader = bufzilla.Reader(.{}).init(slice); var reader = bufzilla.Reader(.{}).init(slice);
const id = try reader.readPath("id"); const id = try reader.readPath("id");
@ -119,6 +139,8 @@ pub fn main() !void {
}, },
}; };
rl.pollInputEvents();
if (peer.state() == .connected) { if (peer.state() == .connected) {
const packet = try znet.Packet.init("Hello, Server!", 0, .reliable); const packet = try znet.Packet.init("Hello, Server!", 0, .reliable);
try peer.send(packet); try peer.send(packet);
@ -132,15 +154,36 @@ pub fn main() !void {
rl.updateMusicStream(music); rl.updateMusicStream(music);
while (accumulator > dt * k) {
// update(dt * cast(float) k);
accumulator -= dt * k;
gt += dt * k;
}
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.clearBackground(.sky_blue); rl.clearBackground(.sky_blue);
rl.beginDrawing(); rl.beginDrawing();
const connected_text = "Connected";
const not_connected_text = "Not Connected";
const f = try rl.getFontDefault();
std.log.info("baseSize: {}, text length: {}", .{f.baseSize, rl.measureText(connected_text, f.baseSize)});
switch (peer.state()) {
.connected => rl.drawText(connected_text, @divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50, 20, .white),
else => rl.drawText(not_connected_text, @divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(not_connected_text, f.baseSize), 1), 50, 20, .white),
}
rl.drawLineV(.{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = 0}, .{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = @floatFromInt(rl.getScreenHeight())}, .red);
rl.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white); rl.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white);
rl.drawRectangleLines(0, 0, 100, 100, .red); rl.drawRectangleLines(0, 0, 100, 100, .red);
rl.drawFPS(0, 0); misc.drawFPS(0, 0, frame_time, frame);
elf.draw(); elf.draw();
// rl.beginMode3D(camera); // rl.beginMode3D(camera);
@ -150,6 +193,8 @@ pub fn main() !void {
rl.endDrawing(); rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.swapScreenBuffer();
} }
} }

View File

@ -7,6 +7,13 @@ const shared = @import("shared");
const chunk = @import("chunk.zig"); const chunk = @import("chunk.zig");
const server = @import("server.zig"); const server = @import("server.zig");
const dt : f32 = 1.0 / 200.0;
var t : f32 = 0;
var gt : f32 = 0;
var accumulator : f32 = 0;
var k : f32 = 1.0;
var frame : i32 = 0;
var stdout: *std.io.Writer = undefined; var stdout: *std.io.Writer = undefined;
pub fn main() !void { pub fn main() !void {
@ -43,7 +50,21 @@ pub fn main() !void {
var the_chunk = try shared.chunk.initChunk(allocator); var the_chunk = try shared.chunk.initChunk(allocator);
defer shared.chunk.deinitChunk(&the_chunk, allocator); defer shared.chunk.deinitChunk(&the_chunk, allocator);
var old_time = std.time.nanoTimestamp();
while (true) { while (true) {
const new_time = std.time.nanoTimestamp();
var frame_time : f32 = @as(f32, @floatFromInt(new_time - old_time)) / 1_000_000_000.0;
old_time = new_time;
if (frame_time > 0.25)
frame_time = 0.25;
t += frame_time;
accumulator += frame_time * k;
// std.log.info("t: {}", .{t});
while (try server.host.service(0)) |event| switch (event) { while (try server.host.service(0)) |event| switch (event) {
.connect => |data| { .connect => |data| {
_ = data; _ = data;