mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-09 03:59:53 -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 {
|
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.
|
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:
|
// 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});
|
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 numOfSmoothPixels: u31 = 0;
|
||||||
var x: f32 = 0;
|
var x: f32 = 0;
|
||||||
while(x < 16) : (x += 1) {
|
while(x < 16) : (x += 1) {
|
||||||
var y: f32 = 0;
|
var y: f32 = 0;
|
||||||
while(y < 16) : (y += 1) {
|
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 distance = @cos(angle)*vec.length(center - Vec2f{x + 0.5, y + 0.5});
|
||||||
const deltaAngle = @abs(angle - originalAngle);
|
const deltaAngle = @abs(angle - originalAngle);
|
||||||
const deltaDist = @abs(distance - originalDistance);
|
const deltaDist = @abs(distance - originalDistance);
|
||||||
@ -667,7 +667,7 @@ const ToolPhysics = struct {
|
|||||||
// Additionally the handle is assumed to go towards the center of mass.
|
// 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.
|
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.
|
// 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 leftCollisionAngle: f32 = 0;
|
||||||
var rightCollisionAngle: f32 = 0;
|
var rightCollisionAngle: f32 = 0;
|
||||||
var frontCollisionDistance: f32 = 0;
|
var frontCollisionDistance: f32 = 0;
|
||||||
@ -678,7 +678,7 @@ const ToolPhysics = struct {
|
|||||||
if(tool.materialGrid[x][y] == null) continue;
|
if(tool.materialGrid[x][y] == null) continue;
|
||||||
const x_float: f32 = @floatFromInt(x);
|
const x_float: f32 = @floatFromInt(x);
|
||||||
const y_float: f32 = @floatFromInt(y);
|
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});
|
const distance = @cos(angle)*vec.length(center - Vec2f{x_float + 0.5, y_float + 0.5});
|
||||||
if(angle < leftCollisionAngle) {
|
if(angle < leftCollisionAngle) {
|
||||||
leftCollisionAngle = angle;
|
leftCollisionAngle = angle;
|
||||||
|
@ -51,9 +51,9 @@ fn cacheString(comptime str: []const u8) []const u8 {
|
|||||||
var logFile: ?std.fs.File = undefined;
|
var logFile: ?std.fs.File = undefined;
|
||||||
var supportsANSIColors: bool = undefined;
|
var supportsANSIColors: bool = undefined;
|
||||||
// overwrite the log function:
|
// overwrite the log function:
|
||||||
pub const std_options = struct {
|
pub const std_options: std.Options = .{
|
||||||
pub const log_level = .debug;
|
.log_level = .debug,
|
||||||
pub fn logFn(
|
.logFn = struct {pub fn logFn(
|
||||||
comptime level: std.log.Level,
|
comptime level: std.log.Level,
|
||||||
comptime _: @Type(.EnumLiteral),
|
comptime _: @Type(.EnumLiteral),
|
||||||
comptime format: []const u8,
|
comptime format: []const u8,
|
||||||
@ -178,7 +178,7 @@ pub const std_options = struct {
|
|||||||
resultArgs[resultArgs.len - 1] = colorReset;
|
resultArgs[resultArgs.len - 1] = colorReset;
|
||||||
}
|
}
|
||||||
logToStdErr(formatString, resultArgs);
|
logToStdErr(formatString, resultArgs);
|
||||||
}
|
}}.logFn,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn initLogging() void {
|
fn initLogging() void {
|
||||||
|
@ -49,7 +49,7 @@ const Socket = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: Socket) void {
|
fn deinit(self: Socket) void {
|
||||||
os.closeSocket(self.socketID);
|
os.close(self.socketID);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(self: Socket, data: []const u8, destination: Address) void {
|
fn send(self: Socket, data: []const u8, destination: Address) void {
|
||||||
|
@ -8,25 +8,22 @@ const main = @import("main.zig");
|
|||||||
pub const Compression = struct {
|
pub const Compression = struct {
|
||||||
pub fn deflate(allocator: NeverFailingAllocator, data: []const u8) []u8 {
|
pub fn deflate(allocator: NeverFailingAllocator, data: []const u8) []u8 {
|
||||||
var result = main.List(u8).init(allocator);
|
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.write(data) catch unreachable;
|
||||||
comp.close() catch unreachable;
|
comp.finish() catch unreachable;
|
||||||
comp.deinit();
|
|
||||||
return result.toOwnedSlice();
|
return result.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inflateTo(buf: []u8, data: []const u8) !usize {
|
pub fn inflateTo(buf: []u8, data: []const u8) !usize {
|
||||||
var arena = std.heap.ArenaAllocator.init(main.stackAllocator.allocator);
|
var streamIn = std.io.fixedBufferStream(data);
|
||||||
defer arena.deinit();
|
var decomp = std.compress.flate.decompressor(streamIn.reader());
|
||||||
var stream = std.io.fixedBufferStream(data);
|
var streamOut = std.io.fixedBufferStream(buf);
|
||||||
var decomp = try std.compress.deflate.decompressor(arena.allocator(), stream.reader(), null);
|
try decomp.decompress(streamOut.writer());
|
||||||
defer decomp.deinit();
|
return streamOut.getWritten().len;
|
||||||
return try decomp.reader().readAll(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pack(sourceDir: std.fs.Dir, writer: anytype) !void {
|
pub fn pack(sourceDir: std.fs.Dir, writer: anytype) !void {
|
||||||
var comp = try std.compress.deflate.compressor(main.stackAllocator.allocator, writer, .{.level = .default_compression});
|
var comp = try std.compress.flate.compressor(writer, .{});
|
||||||
defer comp.deinit();
|
|
||||||
var walker = try sourceDir.walk(main.stackAllocator.allocator);
|
var walker = try sourceDir.walk(main.stackAllocator.allocator);
|
||||||
defer walker.deinit();
|
defer walker.deinit();
|
||||||
|
|
||||||
@ -56,13 +53,12 @@ pub const Compression = struct {
|
|||||||
_ = try comp.write(fileData);
|
_ = try comp.write(fileData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try comp.close();
|
try comp.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unpack(outDir: std.fs.Dir, input: []const u8) !void {
|
pub fn unpack(outDir: std.fs.Dir, input: []const u8) !void {
|
||||||
var stream = std.io.fixedBufferStream(input);
|
var stream = std.io.fixedBufferStream(input);
|
||||||
var decomp = try std.compress.deflate.decompressor(main.stackAllocator.allocator, stream.reader(), null);
|
var decomp = std.compress.flate.decompressor(stream.reader());
|
||||||
defer decomp.deinit();
|
|
||||||
const reader = decomp.reader();
|
const reader = decomp.reader();
|
||||||
const _data = try reader.readAllAlloc(main.stackAllocator.allocator, std.math.maxInt(usize));
|
const _data = try reader.readAllAlloc(main.stackAllocator.allocator, std.math.maxInt(usize));
|
||||||
defer main.stackAllocator.free(_data);
|
defer main.stackAllocator.free(_data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user