add logging
This commit is contained in:
parent
ff1bcaa7dc
commit
c3cd0f5aa9
57
src/main.zig
57
src/main.zig
@ -2,35 +2,21 @@ const std = @import("std");
|
|||||||
const rl = @import("raylib");
|
const rl = @import("raylib");
|
||||||
const rg = @import("raygui");
|
const rg = @import("raygui");
|
||||||
const pr = @import("primitives.zig");
|
const pr = @import("primitives.zig");
|
||||||
|
const plot = @import("plot.zig");
|
||||||
|
|
||||||
const allocator = std.heap.page_allocator;
|
const allocator = std.heap.page_allocator;
|
||||||
|
var prng = std.rand.DefaultPrng.init(124346234556);
|
||||||
var prng = std.rand.DefaultPrng.init(124346556);
|
|
||||||
|
|
||||||
const rand = prng.random();
|
const rand = prng.random();
|
||||||
|
|
||||||
|
const screenWidth = 1200;
|
||||||
|
const screenHeight = 800;
|
||||||
|
|
||||||
fn randMinMaxFloat(min: f32, max: f32) f32 {
|
fn randMinMaxFloat(min: f32, max: f32) f32 {
|
||||||
var r1 = rand.float(f32);
|
var r1 = rand.float(f32);
|
||||||
r1 = 2 * (r1 - 0.5); //-0.5..0.5
|
r1 = 2 * (r1 - 0.5); //-0.5..0.5
|
||||||
return (@abs(min) + @abs(max)) / 2 * r1;
|
return (@abs(min) + @abs(max)) / 2 * r1;
|
||||||
}
|
}
|
||||||
|
|
||||||
test "random" {
|
|
||||||
var seed: u64 = undefined;
|
|
||||||
var r1: f32 = undefined;
|
|
||||||
try std.posix.getrandom(std.mem.asBytes(&seed));
|
|
||||||
|
|
||||||
prng = std.rand.DefaultPrng.init(seed);
|
|
||||||
while (true) {
|
|
||||||
r1 = randMinMaxFloat(-10, 10);
|
|
||||||
//std.debug.print("randMinMaxFloat:{}\n",.{r1});
|
|
||||||
if (r1 > 8 or r1 < -8) {
|
|
||||||
std.debug.print("Greater:{}\n", .{r1});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const screenWidth = 1200;
|
|
||||||
const screenHeight = 800;
|
|
||||||
|
|
||||||
const Particle = struct {
|
const Particle = struct {
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
position: pr.Vec = .{ .a = .{ .x = 0, .y = 0, .z = 0 } },
|
position: pr.Vec = .{ .a = .{ .x = 0, .y = 0, .z = 0 } },
|
||||||
@ -193,6 +179,12 @@ pub fn main() anyerror!void {
|
|||||||
|
|
||||||
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
|
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
|
||||||
|
const file = try plot.open("plot.dat");
|
||||||
|
try plot.log(file,"test\ntest2\n");
|
||||||
|
|
||||||
|
var plotStr : []u8 = undefined;
|
||||||
|
var plotStrBuf : [128]u8 = undefined;
|
||||||
|
|
||||||
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
|
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
|
||||||
rl.beginDrawing();
|
rl.beginDrawing();
|
||||||
defer rl.endDrawing();
|
defer rl.endDrawing();
|
||||||
@ -211,11 +203,17 @@ pub fn main() anyerror!void {
|
|||||||
if (rl.isMouseButtonDown(rl.MouseButton.mouse_button_left)) {
|
if (rl.isMouseButtonDown(rl.MouseButton.mouse_button_left)) {
|
||||||
emitter.emit(@as(u32, @intFromFloat(value)), value2, value3);
|
emitter.emit(@as(u32, @intFromFloat(value)), value2, value3);
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.beginBlendMode(rl.BlendMode.blend_additive);
|
rl.beginBlendMode(rl.BlendMode.blend_additive);
|
||||||
emitter.update(texture);
|
|
||||||
rl.endBlendMode();
|
rl.endBlendMode();
|
||||||
|
|
||||||
|
plotStr = try std.fmt.bufPrint(&plotStrBuf,"{}, {}, {}\n",.{emitter.particles[0].acceleration.a.x,emitter.particles[0].position.a.x,emitter.particles[0].velocity.a.x});
|
||||||
|
try plot.log(file,plotStr);
|
||||||
|
|
||||||
|
emitter.update(texture);
|
||||||
}
|
}
|
||||||
|
plot.close(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "simple test" {
|
test "simple test" {
|
||||||
@ -224,3 +222,18 @@ test "simple test" {
|
|||||||
try list.append(42);
|
try list.append(42);
|
||||||
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "random" {
|
||||||
|
var seed: u64 = undefined;
|
||||||
|
var r1: f32 = undefined;
|
||||||
|
try std.posix.getrandom(std.mem.asBytes(&seed));
|
||||||
|
|
||||||
|
prng = std.rand.DefaultPrng.init(seed);
|
||||||
|
while (true) {
|
||||||
|
r1 = randMinMaxFloat(-10, 10);
|
||||||
|
//std.debug.print("randMinMaxFloat:{}\n",.{r1});
|
||||||
|
if (r1 > 8 or r1 < -8) {
|
||||||
|
std.debug.print("Greater:{}\n", .{r1});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
16
src/plot.zig
Normal file
16
src/plot.zig
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn log(self : std.fs.File,data : []const u8) !void
|
||||||
|
{
|
||||||
|
try self.writeAll(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open(file : []const u8) !std.fs.File
|
||||||
|
{
|
||||||
|
const fileh = try std.fs.cwd().createFile(file,.{.read = true});
|
||||||
|
return fileh;
|
||||||
|
}
|
||||||
|
pub fn close(file : std.fs.File) void
|
||||||
|
{
|
||||||
|
file.close();
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user