mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Update Zig
This commit is contained in:
parent
dcb63fe175
commit
3ae9921de8
@ -1 +1 @@
|
||||
0.12.0-dev.2150+63de8a598
|
||||
0.12.0-dev.3142+9d500bda2
|
@ -641,14 +641,14 @@ const ToolPhysics = struct {
|
||||
fn determineSharpness(tool: *Tool, point: *Vec3i, initialAngle: f32) void {
|
||||
const center: Vec2f = tool.handlePosition - vec.normalize(tool.centerOfMass - tool.handlePosition)*@as(Vec2f, @splat(16)); // Going 16 pixels away from the handle to simulate arm length.
|
||||
// A region is smooth if there is a lot of pixel within similar angle/distance:
|
||||
const originalAngle = std.math.atan2(f32, @as(f32, @floatFromInt(point.*[1])) + 0.5 - center[1], @as(f32, @floatFromInt(point.*[0])) + 0.5 - center[0]) - initialAngle;
|
||||
const originalAngle = std.math.atan2(@as(f32, @floatFromInt(point.*[1])) + 0.5 - center[1], @as(f32, @floatFromInt(point.*[0])) + 0.5 - center[0]) - initialAngle;
|
||||
const originalDistance = @cos(originalAngle)*vec.length(center - Vec2f{@as(f32, @floatFromInt(point.*[0])) + 0.5, @as(f32, @floatFromInt(point.*[1])) + 0.5});
|
||||
var numOfSmoothPixels: u31 = 0;
|
||||
var x: f32 = 0;
|
||||
while(x < 16) : (x += 1) {
|
||||
var y: f32 = 0;
|
||||
while(y < 16) : (y += 1) {
|
||||
const angle = std.math.atan2(f32, y + 0.5 - center[1], x + 0.5 - center[0]) - initialAngle;
|
||||
const angle = std.math.atan2(y + 0.5 - center[1], x + 0.5 - center[0]) - initialAngle;
|
||||
const distance = @cos(angle)*vec.length(center - Vec2f{x + 0.5, y + 0.5});
|
||||
const deltaAngle = @abs(angle - originalAngle);
|
||||
const deltaDist = @abs(distance - originalDistance);
|
||||
@ -667,7 +667,7 @@ const ToolPhysics = struct {
|
||||
// Additionally the handle is assumed to go towards the center of mass.
|
||||
const center: Vec2f = tool.handlePosition - vec.normalize(tool.centerOfMass - tool.handlePosition)*@as(Vec2f, @splat(factor)); // Going some distance away from the handle to simulate arm length.
|
||||
// Angle of the handle.
|
||||
const initialAngle = std.math.atan2(f32, tool.handlePosition[1] - center[1], tool.handlePosition[0] - center[0]);
|
||||
const initialAngle = std.math.atan2(tool.handlePosition[1] - center[1], tool.handlePosition[0] - center[0]);
|
||||
var leftCollisionAngle: f32 = 0;
|
||||
var rightCollisionAngle: f32 = 0;
|
||||
var frontCollisionDistance: f32 = 0;
|
||||
@ -678,7 +678,7 @@ const ToolPhysics = struct {
|
||||
if(tool.materialGrid[x][y] == null) continue;
|
||||
const x_float: f32 = @floatFromInt(x);
|
||||
const y_float: f32 = @floatFromInt(y);
|
||||
const angle = std.math.atan2(f32, y_float + 0.5 - center[1], x_float + 0.5 - center[0]) - initialAngle;
|
||||
const angle = std.math.atan2(y_float + 0.5 - center[1], x_float + 0.5 - center[0]) - initialAngle;
|
||||
const distance = @cos(angle)*vec.length(center - Vec2f{x_float + 0.5, y_float + 0.5});
|
||||
if(angle < leftCollisionAngle) {
|
||||
leftCollisionAngle = angle;
|
||||
|
@ -51,9 +51,9 @@ fn cacheString(comptime str: []const u8) []const u8 {
|
||||
var logFile: ?std.fs.File = undefined;
|
||||
var supportsANSIColors: bool = undefined;
|
||||
// overwrite the log function:
|
||||
pub const std_options = struct {
|
||||
pub const log_level = .debug;
|
||||
pub fn logFn(
|
||||
pub const std_options: std.Options = .{
|
||||
.log_level = .debug,
|
||||
.logFn = struct {pub fn logFn(
|
||||
comptime level: std.log.Level,
|
||||
comptime _: @Type(.EnumLiteral),
|
||||
comptime format: []const u8,
|
||||
@ -178,7 +178,7 @@ pub const std_options = struct {
|
||||
resultArgs[resultArgs.len - 1] = colorReset;
|
||||
}
|
||||
logToStdErr(formatString, resultArgs);
|
||||
}
|
||||
}}.logFn,
|
||||
};
|
||||
|
||||
fn initLogging() void {
|
||||
|
@ -49,7 +49,7 @@ const Socket = struct {
|
||||
}
|
||||
|
||||
fn deinit(self: Socket) void {
|
||||
os.closeSocket(self.socketID);
|
||||
os.close(self.socketID);
|
||||
}
|
||||
|
||||
fn send(self: Socket, data: []const u8, destination: Address) void {
|
||||
|
@ -8,25 +8,22 @@ const main = @import("main.zig");
|
||||
pub const Compression = struct {
|
||||
pub fn deflate(allocator: NeverFailingAllocator, data: []const u8) []u8 {
|
||||
var result = main.List(u8).init(allocator);
|
||||
var comp = std.compress.deflate.compressor(main.stackAllocator.allocator, result.writer(), .{.level = .default_compression}) catch unreachable;
|
||||
var comp = std.compress.flate.compressor(result.writer(), .{}) catch unreachable;
|
||||
_ = comp.write(data) catch unreachable;
|
||||
comp.close() catch unreachable;
|
||||
comp.deinit();
|
||||
comp.finish() catch unreachable;
|
||||
return result.toOwnedSlice();
|
||||
}
|
||||
|
||||
pub fn inflateTo(buf: []u8, data: []const u8) !usize {
|
||||
var arena = std.heap.ArenaAllocator.init(main.stackAllocator.allocator);
|
||||
defer arena.deinit();
|
||||
var stream = std.io.fixedBufferStream(data);
|
||||
var decomp = try std.compress.deflate.decompressor(arena.allocator(), stream.reader(), null);
|
||||
defer decomp.deinit();
|
||||
return try decomp.reader().readAll(buf);
|
||||
var streamIn = std.io.fixedBufferStream(data);
|
||||
var decomp = std.compress.flate.decompressor(streamIn.reader());
|
||||
var streamOut = std.io.fixedBufferStream(buf);
|
||||
try decomp.decompress(streamOut.writer());
|
||||
return streamOut.getWritten().len;
|
||||
}
|
||||
|
||||
pub fn pack(sourceDir: std.fs.Dir, writer: anytype) !void {
|
||||
var comp = try std.compress.deflate.compressor(main.stackAllocator.allocator, writer, .{.level = .default_compression});
|
||||
defer comp.deinit();
|
||||
var comp = try std.compress.flate.compressor(writer, .{});
|
||||
var walker = try sourceDir.walk(main.stackAllocator.allocator);
|
||||
defer walker.deinit();
|
||||
|
||||
@ -56,13 +53,12 @@ pub const Compression = struct {
|
||||
_ = try comp.write(fileData);
|
||||
}
|
||||
}
|
||||
try comp.close();
|
||||
try comp.finish();
|
||||
}
|
||||
|
||||
pub fn unpack(outDir: std.fs.Dir, input: []const u8) !void {
|
||||
var stream = std.io.fixedBufferStream(input);
|
||||
var decomp = try std.compress.deflate.decompressor(main.stackAllocator.allocator, stream.reader(), null);
|
||||
defer decomp.deinit();
|
||||
var decomp = std.compress.flate.decompressor(stream.reader());
|
||||
const reader = decomp.reader();
|
||||
const _data = try reader.readAllAlloc(main.stackAllocator.allocator, std.math.maxInt(usize));
|
||||
defer main.stackAllocator.free(_data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user