Update zig to 0.11.0-dev.3990+f2d433a19

This commit is contained in:
IntegratedQuantum 2023-07-14 11:24:18 +02:00
parent 6928041259
commit 7cb347ce3c
35 changed files with 127 additions and 127 deletions

View File

@ -303,22 +303,22 @@ pub fn update(deltaTime: f64) !void {
if(keyboard.forward.pressed) {
if(keyboard.sprint.pressed) {
if(Player.isFlying.load(.Monotonic)) {
movement += forward*@splat(3, @as(f64, 128));
movement += forward*@as(Vec3d, @splat(128));
} else {
movement += forward*@splat(3, @as(f64, 8));
movement += forward*@as(Vec3d, @splat(8));
}
} else {
movement += forward*@splat(3, @as(f64, 4));
movement += forward*@as(Vec3d, @splat(4));
}
}
if(keyboard.backward.pressed) {
movement += forward*@splat(3, @as(f64, -4));
movement += forward*@as(Vec3d, @splat(-4));
}
if(keyboard.left.pressed) {
movement += right*@splat(3, @as(f64, 4));
movement += right*@as(Vec3d, @splat(4));
}
if(keyboard.right.pressed) {
movement += right*@splat(3, @as(f64, -4));
movement += right*@as(Vec3d, @splat(-4));
}
if(keyboard.jump.pressed) {
if(Player.isFlying.load(.Monotonic)) {
@ -345,7 +345,7 @@ pub fn update(deltaTime: f64) !void {
{
Player.mutex.lock();
defer Player.mutex.unlock();
Player.super.pos += movement*@splat(3, deltaTime);
Player.super.pos += movement*@as(Vec3d, @splat(deltaTime));
}
try world.?.update();
}

View File

@ -38,7 +38,7 @@ pub const draw = struct {
/// Returns the previous translation.
pub fn setTranslation(newTranslation: Vec2f) Vec2f {
const oldTranslation = translation;
translation += newTranslation*@splat(2, scale);
translation += newTranslation*@as(Vec2f, @splat(scale));
return oldTranslation;
}
@ -142,9 +142,9 @@ pub const draw = struct {
pub fn rect(_pos: Vec2f, _dim: Vec2f) void {
var pos = _pos;
var dim = _dim;
pos *= @splat(2, scale);
pos *= @splat(scale);
pos += translation;
dim *= @splat(2, scale);
dim *= @splat(scale);
rectShader.bind();
@ -194,9 +194,9 @@ pub const draw = struct {
pub fn line(_pos1: Vec2f, _pos2: Vec2f) void {
var pos1 = _pos1;
var pos2 = _pos2;
pos1 *= @splat(2, scale);
pos1 *= @splat(scale);
pos1 += translation;
pos2 *= @splat(2, scale);
pos2 *= @splat(scale);
pos2 += translation;
lineShader.bind();
@ -241,9 +241,9 @@ pub const draw = struct {
pub fn rectOutline(_pos: Vec2f, _dim: Vec2f) void {
var pos = _pos;
var dim = _dim;
pos *= @splat(2, scale);
pos *= @splat(scale);
pos += translation;
dim *= @splat(2, scale);
dim *= @splat(scale);
lineShader.bind();
@ -295,7 +295,7 @@ pub const draw = struct {
pub fn circle(_center: Vec2f, _radius: f32) void {
var center = _center;
var radius = _radius;
_center *= @splat(2, scale);
_center *= @splat(scale);
_center += translation;
radius *= scale;
circleShader.bind();
@ -332,9 +332,9 @@ pub const draw = struct {
pub fn boundImage(_pos: Vec2f, _dim: Vec2f) void {
var pos = _pos;
var dim = _dim;
pos *= @splat(2, scale);
pos *= @splat(scale);
pos += translation;
dim *= @splat(2, scale);
dim *= @splat(scale);
pos = @floor(pos);
dim = @ceil(dim);
@ -354,9 +354,9 @@ pub const draw = struct {
pub fn customShadedRect(uniforms: anytype, _pos: Vec2f, _dim: Vec2f) void {
var pos = _pos;
var dim = _dim;
pos *= @splat(2, scale);
pos *= @splat(scale);
pos += translation;
dim *= @splat(2, scale);
dim *= @splat(scale);
pos = @floor(pos);
dim = @ceil(dim);
@ -376,7 +376,7 @@ pub const draw = struct {
try TextRendering.renderText(_text, x, y, fontSize, .{.color = @truncate(@as(u32, @bitCast(color)))}, alignment);
}
pub fn print(comptime format: []const u8, args: anytype, x: f32, y: f32, fontSize: f32, alignment: TextBuffer.Alignment) !void {
pub inline fn print(comptime format: []const u8, args: anytype, x: f32, y: f32, fontSize: f32, alignment: TextBuffer.Alignment) !void {
var stackFallback = std.heap.stackFallback(4096, main.threadAllocator);
const allocator = stackFallback.get();
const string = try std.fmt.allocPrint(allocator, format, args);

View File

@ -129,7 +129,7 @@ pub fn defaultFunction() void {}
pub fn defaultErrorFunction() Allocator.Error!void {}
pub fn mainButtonPressed(self: *const GuiWindow, mousePosition: Vec2f) void {
const scaledMousePos = (mousePosition - self.pos)/@splat(2, self.scale);
const scaledMousePos = (mousePosition - self.pos)/@as(Vec2f, @splat(self.scale));
if(scaledMousePos[1] < 16 and (self.showTitleBar or self.titleBarExpanded or (!main.Window.grabbed and scaledMousePos[0] < 16))) {
grabbedWindow = self;
grabPosition = mousePosition;
@ -184,7 +184,7 @@ pub fn mainButtonReleased(self: *GuiWindow, mousePosition: Vec2f) void {
grabPosition = null;
grabbedWindow = undefined;
if(self.rootComponent) |*component| {
component.mainButtonReleased((mousePosition - self.pos)/@splat(2, self.scale));
component.mainButtonReleased((mousePosition - self.pos)/@as(Vec2f, @splat(self.scale)));
}
}
@ -247,7 +247,7 @@ fn snapToOtherWindow(self: *GuiWindow) void {
}
fn positionRelativeToFrame(self: *GuiWindow) void {
const windowSize = main.Window.getWindowSize()/@splat(2, gui.scale);
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
for(&self.relativePosition, 0..) |*relPos, i| {
// Snap to the center:
if(@fabs(self.pos[i] + self.size[i] - windowSize[i]/2) <= snapDistance) {
@ -326,7 +326,7 @@ pub fn update(self: *GuiWindow) !void {
pub fn updateSelected(self: *GuiWindow, mousePosition: Vec2f) !void {
try self.updateSelectedFn();
const windowSize = main.Window.getWindowSize()/@splat(2, gui.scale);
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
if(self == grabbedWindow) if(grabPosition) |_grabPosition| {
self.relativePosition[0] = .{.ratio = undefined};
self.relativePosition[1] = .{.ratio = undefined};
@ -351,15 +351,15 @@ pub fn updateSelected(self: *GuiWindow, mousePosition: Vec2f) !void {
pub fn updateHovered(self: *GuiWindow, mousePosition: Vec2f) !void {
try self.updateHoveredFn();
if(self.rootComponent) |component| {
if(GuiComponent.contains(component.pos(), component.size(), (mousePosition - self.pos)/@splat(2, self.scale))) {
component.updateHovered((mousePosition - self.pos)/@splat(2, self.scale));
if(GuiComponent.contains(component.pos(), component.size(), (mousePosition - self.pos)/@as(Vec2f, @splat(self.scale)))) {
component.updateHovered((mousePosition - self.pos)/@as(Vec2f, @splat(self.scale)));
}
}
}
pub fn updateWindowPosition(self: *GuiWindow) void {
self.size = self.contentSize*@splat(2, self.scale);
const windowSize = main.Window.getWindowSize()/@splat(2, gui.scale);
self.size = self.contentSize*@as(Vec2f, @splat(self.scale));
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
for(self.relativePosition, 0..) |relPos, i| {
switch(relPos) {
.ratio => |ratio| {
@ -405,7 +405,7 @@ pub fn updateWindowPosition(self: *GuiWindow) void {
fn drawOrientationLines(self: *const GuiWindow) void {
draw.setColor(0x80000000);
const windowSize = main.Window.getWindowSize()/@splat(2, gui.scale);
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
for(self.relativePosition, 0..) |relPos, i| {
switch(relPos) {
.ratio, .relativeToWindow => {
@ -457,11 +457,11 @@ pub fn render(self: *const GuiWindow, mousePosition: Vec2f) !void {
draw.setColor(0xff000000);
shader.bind();
backgroundTexture.bindTo(0);
draw.customShadedRect(windowUniforms, .{0, 0}, self.size/@splat(2, self.scale));
draw.customShadedRect(windowUniforms, .{0, 0}, self.size/@as(Vec2f, @splat(self.scale)));
}
try self.renderFn();
if(self.rootComponent) |*component| {
try component.render((mousePosition - self.pos)/@splat(2, self.scale));
try component.render((mousePosition - self.pos)/@as(Vec2f, @splat(self.scale)));
}
if(self.showTitleBar) {
shader.bind();
@ -490,7 +490,7 @@ pub fn render(self: *const GuiWindow, mousePosition: Vec2f) !void {
draw.setColor(0x80000000);
borderShader.bind();
graphics.c.glUniform2f(borderUniforms.effectLength, 2.5, 2.5);
draw.customShadedRect(borderUniforms, .{0, 0}, self.size/@splat(2, self.scale));
draw.customShadedRect(borderUniforms, .{0, 0}, self.size/@as(Vec2f, @splat(self.scale)));
}
draw.restoreTranslation(oldTranslation);
draw.restoreScale(oldScale);

View File

@ -71,7 +71,7 @@ pub fn initIcon(pos: Vec2f, iconSize: Vec2f, iconTexture: Texture, hasShadow: bo
const self = try main.globalAllocator.create(Button);
self.* = Button {
.pos = pos,
.size = icon.size + @splat(2, 3*border),
.size = icon.size + @as(Vec2f, @splat(3*border)),
.onAction = onAction,
.child = icon.toComponent(),
};
@ -121,7 +121,7 @@ pub fn render(self: *Button, mousePosition: Vec2f) anyerror!void { // TODO: Remo
self.hovered = false;
draw.customShadedRect(buttonUniforms, self.pos, self.size);
graphics.c.glUniform1i(buttonUniforms.pressed, 0);
const textPos = self.pos + self.size/@splat(2, @as(f32, 2.0)) - self.child.size()/@splat(2, @as(f32, 2.0));
const textPos = self.pos + self.size/@as(Vec2f, @splat(2.0)) - self.child.size()/@as(Vec2f, @splat(2.0));
self.child.mutPos().* = textPos;
try self.child.render(mousePosition - self.pos);
}

View File

@ -102,9 +102,9 @@ pub fn render(self: *CheckBox, mousePosition: Vec2f) !void {
draw.setColor(0xff000000);
}
self.hovered = false;
draw.customShadedRect(Button.buttonUniforms, self.pos + Vec2f{0, self.size[1]/2 - boxSize/2}, @splat(2, boxSize));
draw.customShadedRect(Button.buttonUniforms, self.pos + Vec2f{0, self.size[1]/2 - boxSize/2}, @as(Vec2f, @splat(boxSize)));
graphics.c.glUniform1i(Button.buttonUniforms.pressed, 0);
const textPos = self.pos + Vec2f{boxSize/2, 0} + self.size/@splat(2, @as(f32, 2.0)) - self.label.size/@splat(2, @as(f32, 2.0));
const textPos = self.pos + Vec2f{boxSize/2, 0} + self.size/@as(Vec2f, @splat(2.0)) - self.label.size/@as(Vec2f, @splat(2.0));
self.label.pos = textPos;
try self.label.render(mousePosition - textPos);
}

View File

@ -133,7 +133,7 @@ pub fn render(self: *ContinuousSlider, mousePosition: Vec2f) !void {
draw.setColor(0x80000000);
draw.rect(self.pos + Vec2f{1.5*border + self.button.size[0]/2, self.button.pos[1] + self.button.size[1]/2 - border}, .{range, 2*border});
self.label.pos = self.pos + @splat(2, 1.5*border);
self.label.pos = self.pos + @as(Vec2f, @splat(1.5*border));
try self.label.render(mousePosition);
if(self.button.pressed) {

View File

@ -93,9 +93,9 @@ pub fn render(self: *CraftingResultSlot, _: Vec2f) !void {
const itemTexture = try item.getTexture();
itemTexture.bindTo(0);
draw.setColor(0xff000000);
draw.boundImage(self.pos + @splat(2, border) + Vec2f{1.0, 1.0}, self.size - @splat(2, 2*border));
draw.boundImage(self.pos + @as(Vec2f, @splat(border)) + Vec2f{1.0, 1.0}, self.size - @as(Vec2f, @splat(2*border)));
draw.setColor(0xffffffff);
draw.boundImage(self.pos + @splat(2, border), self.size - @splat(2, 2*border));
draw.boundImage(self.pos + @as(Vec2f, @splat(border)), self.size - @as(Vec2f, @splat(2*border)));
if(self.itemStack.amount != 1) {
try self.text.render(self.pos[0] + self.size[0] - self.textSize[0] - border, self.pos[1] + self.size[1] - self.textSize[1] - border, 8);
}

View File

@ -147,7 +147,7 @@ pub fn render(self: *DiscreteSlider, mousePosition: Vec2f) !void {
draw.setColor(0x80000000);
draw.rect(self.pos + Vec2f{1.5*border + self.button.size[0]/2, self.button.pos[1] + self.button.size[1]/2 - border}, .{range, 2*border});
self.label.pos = self.pos + @splat(2, 1.5*border);
self.label.pos = self.pos + @as(Vec2f, @splat(1.5*border));
try self.label.render(mousePosition);
if(self.button.pressed) {

View File

@ -64,9 +64,9 @@ pub fn render(self: *ImmutableItemSlot, _: Vec2f) !void {
const itemTexture = try self.item.getTexture();
itemTexture.bindTo(0);
draw.setColor(0xff000000);
draw.boundImage(self.pos + @splat(2, border) + Vec2f{1.0, 1.0}, self.size - @splat(2, 2*border));
draw.boundImage(self.pos + @as(Vec2f, @splat(border)) + Vec2f{1.0, 1.0}, self.size - @as(Vec2f, @splat(2*border)));
draw.setColor(0xffffffff);
draw.boundImage(self.pos + @splat(2, border), self.size - @splat(2, 2*border));
draw.boundImage(self.pos + @as(Vec2f, @splat(border)), self.size - @as(Vec2f, @splat(2*border)));
if(self.amount != 1) {
try self.text.render(self.pos[0] + self.size[0] - self.textSize[0] - border, self.pos[1] + self.size[1] - self.textSize[1] - border, 8);
}

View File

@ -129,9 +129,9 @@ pub fn render(self: *ItemSlot, _: Vec2f) !void {
const itemTexture = try item.getTexture();
itemTexture.bindTo(0);
draw.setColor(0xff000000);
draw.boundImage(self.pos + @splat(2, border) + Vec2f{1.0, 1.0}, self.size - @splat(2, 2*border));
draw.boundImage(self.pos + @as(Vec2f, @splat(border)) + Vec2f{1.0, 1.0}, self.size - @as(Vec2f, @splat(2*border)));
draw.setColor(0xffffffff);
draw.boundImage(self.pos + @splat(2, border), self.size - @splat(2, 2*border));
draw.boundImage(self.pos + @as(Vec2f, @splat(border)), self.size - @as(Vec2f, @splat(2*border)));
if(self.itemStack.amount != 1) {
try self.text.render(self.pos[0] + self.size[0] - self.textSize[0] - border, self.pos[1] + self.size[1] - self.textSize[1] - border, 8);
}

View File

@ -453,7 +453,7 @@ pub fn mainButtonPressed() void {
selectedTextInput = null;
var selectedI: usize = 0;
for(openWindows.items, 0..) |window, i| {
var mousePosition = main.Window.getMousePosition()/@splat(2, scale);
var mousePosition = main.Window.getMousePosition()/@as(Vec2f, @splat(scale));
mousePosition -= window.pos;
if(@reduce(.And, mousePosition >= Vec2f{0, 0}) and @reduce(.And, mousePosition < window.size)) {
selectedWindow = window;
@ -461,7 +461,7 @@ pub fn mainButtonPressed() void {
}
}
if(selectedWindow) |_selectedWindow| {
const mousePosition = main.Window.getMousePosition()/@splat(2, scale);
const mousePosition = main.Window.getMousePosition()/@as(Vec2f, @splat(scale));
_selectedWindow.mainButtonPressed(mousePosition);
_ = openWindows.orderedRemove(selectedI);
openWindows.appendAssumeCapacity(_selectedWindow);
@ -476,7 +476,7 @@ pub fn mainButtonReleased() void {
var oldWindow = selectedWindow;
selectedWindow = null;
for(openWindows.items) |window| {
var mousePosition = main.Window.getMousePosition()/@splat(2, scale);
var mousePosition = main.Window.getMousePosition()/@as(Vec2f, @splat(scale));
mousePosition -= window.pos;
if(@reduce(.And, mousePosition >= Vec2f{0, 0}) and @reduce(.And, mousePosition < window.size)) {
selectedWindow = window;
@ -486,7 +486,7 @@ pub fn mainButtonReleased() void {
selectedWindow = null;
}
if(oldWindow) |_oldWindow| {
const mousePosition = main.Window.getMousePosition()/@splat(2, scale);
const mousePosition = main.Window.getMousePosition()/@as(Vec2f, @splat(scale));
_oldWindow.mainButtonReleased(mousePosition);
}
}
@ -518,7 +518,7 @@ pub fn updateWindowPositions() void {
}
pub fn updateAndRenderGui() !void {
const mousePos = main.Window.getMousePosition()/@splat(2, scale);
const mousePos = main.Window.getMousePosition()/@as(Vec2f, @splat(scale));
hoveredAWindow = false;
try GuiCommandQueue.executeCommands();
if(!main.Window.grabbed) {
@ -681,9 +681,9 @@ pub const inventory = struct {
const border1: f32 = 2;
const border2: f32 = 1;
draw.setColor(0xffffff00);
draw.rect(pos - @splat(2, border1), size + @splat(2, 2*border1));
draw.rect(pos - @as(Vec2f, @splat(border1)), size + @as(Vec2f, @splat(2*border1)));
draw.setColor(0xff000000);
draw.rect(pos - @splat(2, border2), size + @splat(2, 2*border2));
draw.rect(pos - @as(Vec2f, @splat(border2)), size + @as(Vec2f, @splat(2*border2)));
try textBuffer.render(pos[0], pos[1], 16);
}
};

View File

@ -58,7 +58,7 @@ pub fn onOpen() Allocator.Error!void {
try list.add(try Button.initText(.{0, 0}, 100, "Apply", .{.callback = &apply}));
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -52,7 +52,7 @@ fn refresh() Allocator.Error!void {
list.scrollBar.currentState = 1;
try mutexComponent.updateInner(list);
window.rootComponent = mutexComponent.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -52,7 +52,7 @@ pub fn onOpen() Allocator.Error!void {
}
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -63,7 +63,7 @@ pub fn onOpen() Allocator.Error!void {
}
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, padding);
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -48,7 +48,7 @@ pub fn onOpen() Allocator.Error!void {
try list.add(try CheckBox.init(.{0, 0}, 128, "Vertical Synchronization", settings.vsync, &vsyncCallback));
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -105,7 +105,7 @@ pub fn onOpen() Allocator.Error!void {
}
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, padding);
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -147,7 +147,7 @@ fn refresh() Allocator.Error!void {
}
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, padding);
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -25,7 +25,7 @@ pub fn onOpen() Allocator.Error!void {
try list.add(try Button.initText(.{0, 0}, 128, "Exit TODO", .{}));
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -95,7 +95,7 @@ pub fn onOpen() Allocator.Error!void {
try list.add(try Button.initText(.{0, 0}, 100, "Join", .{.callback = &join}));
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
thread = std.Thread.spawn(.{}, discoverIpAddressFromNewThread, .{}) catch |err| blk: {

View File

@ -60,10 +60,10 @@ fn flawedRender() !void {
graphics.c.glUniform1i(uniforms.offset, index);
graphics.c.glUniform3f(uniforms.lineColor, 1, 1, 1);
var pos = Vec2f{border, border};
var dim = window.contentSize - @splat(2, 2*border);
pos *= @splat(2, draw.setScale(1));
var dim = window.contentSize - @as(Vec2f, @splat(2*border));
pos *= @splat(draw.setScale(1));
pos += draw.setTranslation(.{0, 0});
dim *= @splat(2, draw.setScale(1));
dim *= @splat(draw.setScale(1));
pos = @floor(pos);
dim = @ceil(dim);
pos[1] += dim[1];

View File

@ -137,7 +137,7 @@ pub fn onOpen() Allocator.Error!void {
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -25,7 +25,7 @@ pub fn onOpen() Allocator.Error!void {
try list.add(try Button.initText(.{0, 0}, 128, "Change Name", gui.openWindowCallback("change_name")));
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -45,7 +45,7 @@ pub fn onOpen() Allocator.Error!void {
try list.add(try ContinuousSlider.init(.{0, 0}, 128, -60, 0, linearToDezibel(settings.musicVolume), &musicCallback, &musicFormatter));
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
}

View File

@ -146,7 +146,7 @@ pub fn onOpen() Allocator.Error!void {
try list.add(craftingResult);
list.finish(.{padding, padding + 16}, .center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, padding);
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
gui.updateWindowPositions();
try refresh();
}

View File

@ -229,7 +229,7 @@ pub const ItemDropManager = struct {
@floatCast(random.nextFloat(&main.seed)),
@floatCast(random.nextFloat(&main.seed)),
@floatCast(random.nextFloat(&main.seed)),
} + @splat(3, @as(f64, radius)),
} + @as(Vec3d, @splat(radius)),
vel,
Vec3f {
2*std.math.pi*random.nextFloat(&main.seed),
@ -352,15 +352,15 @@ pub const ItemDropManager = struct {
}
// Apply drag:
vel.* += acceleration;
vel.* *= @splat(3, @max(0, 1 - drag*deltaTime));
vel.* *= @splat(@max(0, 1 - drag*deltaTime));
}
fn fixStuckInBlock(self: *ItemDropManager, chunk: *Chunk, pos: *Vec3d, vel: *Vec3d, deltaTime: f64) void {
std.debug.assert(!self.mutex.tryLock()); // Mutex must be locked!
const centeredPos = pos.* - @splat(3, @as(f64, 0.5));
const centeredPos = pos.* - @as(Vec3d, @splat(0.5));
const pos0 = vec.intFromFloat(i32, @floor(centeredPos));
var closestEmptyBlock = @splat(3, @as(i32, -1));
var closestEmptyBlock: Vec3i = @splat(-1);
var closestDist = std.math.floatMax(f64);
var delta = Vec3i{0, 0, 0};
while(delta[0] <= 1) : (delta[0] += 1) {
@ -380,20 +380,20 @@ pub const ItemDropManager = struct {
}
}
vel.* = @splat(3, @as(f64, 0));
vel.* = @splat(0);
const factor: f64 = 1; // TODO: Investigate what past me wanted to accomplish here.
if(closestDist == std.math.floatMax(f64)) {
// Surrounded by solid blocks move upwards
vel.*[1] = factor;
pos.*[1] += vel.*[1]*deltaTime;
} else {
vel.* = @splat(3, factor)*(vec.floatFromInt(f64, pos0 + closestEmptyBlock) - centeredPos);
pos.* += (vel.*)*@splat(3, deltaTime);
vel.* = @as(Vec3d, @splat(factor))*(vec.floatFromInt(f64, pos0 + closestEmptyBlock) - centeredPos);
pos.* += (vel.*)*@as(Vec3d, @splat(deltaTime));
}
}
fn checkBlocks(self: *ItemDropManager, chunk: *Chunk, pos: *Vec3d) bool {
const lowerCornerPos = pos.* - @splat(3, radius);
const lowerCornerPos = pos.* - @as(Vec3d, @splat(radius));
const pos0f64 = @floor(lowerCornerPos);
const pos0 = vec.intFromFloat(i32, pos0f64);
var isSolid = self.checkBlock(chunk, pos, pos0);
@ -752,8 +752,8 @@ pub const ItemDropRenderer = struct {
// int light = Cubyz.world.getLight(x, y, z, ambientLight, ClientSettings.easyLighting);
const light: u32 = 0xffffffff;
c.glUniform3fv(itemUniforms.ambientLight, 1, @ptrCast(&@max(
ambientLight*@splat(3, @as(f32, @floatFromInt(light >> 24))/255),
Vec3f{light >> 16 & 255, light >> 8 & 255, light & 255}/@splat(3, @as(f32, 255))
ambientLight*@as(Vec3f, @splat(@as(f32, @floatFromInt(light >> 24))/255)),
Vec3f{light >> 16 & 255, light >> 8 & 255, light & 255}/@as(Vec3f, @splat(255))
)));
pos -= playerPos;
var modelMatrix = Mat4f.translation(vec.floatCast(f32, pos));

View File

@ -657,7 +657,7 @@ const ToolPhysics = struct {
}
}
}
tool.centerOfMass = centerOfMass/@splat(2, mass);
tool.centerOfMass = centerOfMass/@as(Vec2f, @splat(mass));
tool.mass = mass;
// Determines the moment of intertia relative to the center of mass:
@ -683,7 +683,7 @@ const ToolPhysics = struct {
/// Determines the sharpness of a point on the tool.
fn determineSharpness(tool: *Tool, point: *Vec3i, initialAngle: f32) void {
const center: Vec2f = tool.handlePosition - vec.normalize(tool.centerOfMass - tool.handlePosition)*@splat(2, @as(f32, 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:
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 originalDistance = @cos(originalAngle)*vec.length(center - Vec2f{@as(f32, @floatFromInt(point.*[0])) + 0.5, @as(f32, @floatFromInt(point.*[1])) + 0.5});
@ -709,7 +709,7 @@ const ToolPhysics = struct {
fn determineCollisionPoints(tool: *Tool, leftCollisionPoint: *Vec3i, rightCollisionPoint: *Vec3i, frontCollisionPoint: *Vec3i, factor: f32) void {
// For finding that point the center of rotation is assumed to be 1 arm(16 pixel) begind the handle.
// Additionally the handle is assumed to go towards the center of mass.
const center: Vec2f = tool.handlePosition - vec.normalize(tool.centerOfMass - tool.handlePosition)*@splat(2, 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.
const initialAngle = std.math.atan2(f32, tool.handlePosition[1] - center[1], tool.handlePosition[0] - center[0]);
var leftCollisionAngle: f32 = 0;

View File

@ -470,12 +470,12 @@ pub const Window = struct {
@floatCast(y),
};
if(grabbed and !ignoreDataAfterRecentGrab) {
deltas[deltaBufferPosition] += (newPos - currentPos)*@splat(2, settings.mouseSensitivity);
deltas[deltaBufferPosition] += (newPos - currentPos)*@as(Vec2f, @splat(settings.mouseSensitivity));
var averagedDelta: Vec2f = Vec2f{0, 0};
for(deltas) |delta| {
averagedDelta += delta;
}
averagedDelta /= @splat(2, @as(f32, deltasLen));
averagedDelta /= @splat(deltasLen);
game.camera.moveRotation(averagedDelta[0]*0.0089, averagedDelta[1]*0.0089);
deltaBufferPosition = (deltaBufferPosition + 1)%deltasLen;
deltas[deltaBufferPosition] = Vec2f{0, 0};

View File

@ -21,8 +21,8 @@ const VoxelModel = extern struct {
pub fn init(self: *VoxelModel, distributionFunction: *const fn(u16, u16, u16) ?u4) void {
if(@sizeOf(VoxelModel) != 16 + 16 + modelSize*modelSize*modelSize*4/8) @compileError("Expected Vec3i to have 16 byte alignment.");
@memset(&self.bitPackedData, 0);
self.min = @splat(3, @as(i32, 16));
self.max = @splat(3, @as(i32, 0));
self.min = @splat(16);
self.max = @splat(0);
var x: u16 = 0;
while(x < modelSize): (x += 1) {
var y: u16 = 0;

View File

@ -195,7 +195,7 @@ pub fn render(playerPosition: Vec3d) !void {
// TODO:
// Cubyz.fog.setActive(ClientSettings.FOG_COEFFICIENT != 0);
// Cubyz.fog.setDensity(1 / (ClientSettings.EFFECTIVE_RENDER_DISTANCE*ClientSettings.FOG_COEFFICIENT));
skyColor *= @splat(3, @as(f32, 0.25));
skyColor *= @splat(0.25);
try renderWorld(world, ambient, skyColor, playerPosition);
try RenderStructure.updateMeshes(startTime + maximumMeshTime);
@ -657,14 +657,14 @@ pub const Frustum = struct {
const halfVSide = _zFar*std.math.tan(std.math.degreesToRadians(f32, fovY)*0.5);
const halfHSide = halfVSide*@as(f32, @floatFromInt(width))/@as(f32, @floatFromInt(height));
const frontMultFar = cameraDir*@splat(3, _zFar);
const frontMultFar = cameraDir*@as(Vec3f, @splat(_zFar));
var self: Frustum = undefined;
self.planes[0] = Plane{.pos = cameraPos + frontMultFar, .norm=-cameraDir}; // far
self.planes[1] = Plane{.pos = cameraPos, .norm=vec.cross(cameraUp, frontMultFar + cameraRight*@splat(3, halfHSide))}; // right
self.planes[2] = Plane{.pos = cameraPos, .norm=vec.cross(frontMultFar - cameraRight*@splat(3, halfHSide), cameraUp)}; // left
self.planes[3] = Plane{.pos = cameraPos, .norm=vec.cross(cameraRight, frontMultFar - cameraUp*@splat(3, halfVSide))}; // top
self.planes[4] = Plane{.pos = cameraPos, .norm=vec.cross(frontMultFar + cameraUp*@splat(3, halfVSide), cameraRight)}; // bottom
self.planes[1] = Plane{.pos = cameraPos, .norm=vec.cross(cameraUp, frontMultFar + cameraRight*@as(Vec3f, @splat(halfHSide)))}; // right
self.planes[2] = Plane{.pos = cameraPos, .norm=vec.cross(frontMultFar - cameraRight*@as(Vec3f, @splat(halfHSide)), cameraUp)}; // left
self.planes[3] = Plane{.pos = cameraPos, .norm=vec.cross(cameraRight, frontMultFar - cameraUp*@as(Vec3f, @splat(halfVSide)))}; // top
self.planes[4] = Plane{.pos = cameraPos, .norm=vec.cross(frontMultFar + cameraUp*@as(Vec3f, @splat(halfVSide)), cameraRight)}; // bottom
return self;
}
@ -755,11 +755,11 @@ pub const MeshSelection = struct {
const closestDistance: f64 = 6.0; // selection now limited
// Implementation of "A Fast Voxel Traversal Algorithm for Ray Tracing" http://www.cse.yorku.ca/~amana/research/grid.pdf
const step = vec.intFromFloat(i32, std.math.sign(dir));
const invDir = @splat(3, @as(f64, 1))/dir;
const invDir = @as(Vec3d, @splat(1))/dir;
const tDelta = @fabs(invDir);
var tMax = (@floor(pos) - pos)*invDir;
tMax = @max(tMax, tMax + tDelta*vec.floatFromInt(f64, step));
tMax = @select(f64, dir == @splat(3, @as(f64, 0)), @splat(3, std.math.inf(f64)), tMax);
tMax = @select(f64, dir == @as(Vec3d, @splat(0)), @as(Vec3d, @splat(std.math.inf(f64))), tMax);
var voxelPos = vec.intFromFloat(i32, @floor(pos));
var total_tMax: f64 = 0;
@ -772,12 +772,12 @@ pub const MeshSelection = struct {
// Check the true bounding box (using this algorithm here: https://tavianator.com/2011/ray_box.html):
const model = blocks.meshes.model(block);
const voxelModel = &models.voxelModels.items[model.modelIndex];
var transformedMin = model.permutation.transform(voxelModel.min - @splat(3, @as(i32, 8))) + @splat(3, @as(i32, 8));
var transformedMax = model.permutation.transform(voxelModel.max - @splat(3, @as(i32, 8))) + @splat(3, @as(i32, 8));
var transformedMin = model.permutation.transform(voxelModel.min - @as(Vec3i, @splat(8))) + @as(Vec3i, @splat(8));
var transformedMax = model.permutation.transform(voxelModel.max - @as(Vec3i, @splat(8))) + @as(Vec3i, @splat(8));
const min = @min(transformedMin, transformedMax);
const max = @max(transformedMin ,transformedMax);
const t1 = (vec.floatFromInt(f64, voxelPos) + vec.floatFromInt(f64, min)/@splat(3, @as(f64, 16.0)) - pos)*invDir;
const t2 = (vec.floatFromInt(f64, voxelPos) + vec.floatFromInt(f64, max)/@splat(3, @as(f64, 16.0)) - pos)*invDir;
const t1 = (vec.floatFromInt(f64, voxelPos) + vec.floatFromInt(f64, min)/@as(Vec3d, @splat(16.0)) - pos)*invDir;
const t2 = (vec.floatFromInt(f64, voxelPos) + vec.floatFromInt(f64, max)/@as(Vec3d, @splat(16.0)) - pos)*invDir;
const boxTMin = @reduce(.Max, @min(t1, t2));
const boxTMax = @reduce(.Min, @max(t1, t2));
if(boxTMin <= boxTMax and boxTMin <= closestDistance and boxTMax > 0) {
@ -898,8 +898,8 @@ pub const MeshSelection = struct {
var block = RenderStructure.getBlock(_selectedBlockPos[0], _selectedBlockPos[1], _selectedBlockPos[2]) orelse return;
const model = blocks.meshes.model(block);
const voxelModel = &models.voxelModels.items[model.modelIndex];
var transformedMin = model.permutation.transform(voxelModel.min - @splat(3, @as(i32, 8))) + @splat(3, @as(i32, 8));
var transformedMax = model.permutation.transform(voxelModel.max - @splat(3, @as(i32, 8))) + @splat(3, @as(i32, 8));
var transformedMin = model.permutation.transform(voxelModel.min - @as(Vec3i, @splat(8))) + @as(Vec3i, @splat(8));
var transformedMax = model.permutation.transform(voxelModel.max - @as(Vec3i, @splat(8))) + @as(Vec3i, @splat(8));
const min = @min(transformedMin, transformedMax);
const max = @max(transformedMin ,transformedMax);
shader.bind();

View File

@ -198,14 +198,14 @@ pub const InterpolatableCaveBiomeMapView = struct {
pub noinline fn interpolateValue(self: InterpolatableCaveBiomeMapView, wx: i32, wy: i32, wz: i32, comptime field: []const u8) f32 {
const worldPos = Vec3i{wx, wy, wz};
const closestGridpoint0 = (worldPos + @splat(3, @as(i32, CaveBiomeMapFragment.caveBiomeSize/2))) & @splat(3, ~@as(i32, CaveBiomeMapFragment.caveBiomeMask));
const closestGridpoint0 = (worldPos + @as(Vec3i, @splat(CaveBiomeMapFragment.caveBiomeSize/2))) & @as(Vec3i, @splat(~@as(i32, CaveBiomeMapFragment.caveBiomeMask)));
const distance0 = worldPos - closestGridpoint0;
const step0 = @select(i32, argMaxDistance0(distance0), @splat(3, @as(i32, CaveBiomeMapFragment.caveBiomeSize)), @splat(3, @as(i32, 0)));
const step0 = @select(i32, argMaxDistance0(distance0), @as(Vec3i, @splat(CaveBiomeMapFragment.caveBiomeSize)), @as(Vec3i, @splat(0)));
const secondGridPoint0 = closestGridpoint0 + step0*nonZeroSign(distance0);
const closestGridpoint1 = (worldPos & @splat(3, ~@as(i32, CaveBiomeMapFragment.caveBiomeMask))) + @splat(3, @as(i32, CaveBiomeMapFragment.caveBiomeSize/2));
const closestGridpoint1 = (worldPos & @as(Vec3i, @splat(~@as(i32, CaveBiomeMapFragment.caveBiomeMask)))) + @as(Vec3i, @splat(CaveBiomeMapFragment.caveBiomeSize/2));
const distance1 = worldPos - closestGridpoint1;
const step1 = @select(i32, argMaxDistance1(distance1), @splat(3, @as(i32, CaveBiomeMapFragment.caveBiomeSize)), @splat(3, @as(i32, 0)));
const step1 = @select(i32, argMaxDistance1(distance1), @as(Vec3i, @splat(CaveBiomeMapFragment.caveBiomeSize)), @as(Vec3i, @splat(0)));
const secondGridPoint1 = closestGridpoint1 + step1*nonZeroSign(distance1);
const @"r⃗₄" = closestGridpoint0;

View File

@ -134,8 +134,8 @@ fn generateCaveBetween(_seed: u64, map: *CaveMapFragment, startWorldPos: Vec3d,
const distance = vec.length(startWorldPos - endWorldPos);
const maxFractalShift = distance*randomness;
const safetyInterval = maxHeight + maxFractalShift;
const min = vec.intFromFloat(i32, @min(startWorldPos, endWorldPos) - @splat(3, safetyInterval));
const max = vec.intFromFloat(i32, @max(startWorldPos, endWorldPos) + @splat(3, safetyInterval));
const min = vec.intFromFloat(i32, @min(startWorldPos, endWorldPos) - @as(Vec3d, @splat(safetyInterval)));
const max = vec.intFromFloat(i32, @max(startWorldPos, endWorldPos) + @as(Vec3d, @splat(safetyInterval)));
// Only divide further if the cave may go through ther considered chunk.
if(min[0] >= map.pos.wx +% CaveMapFragment.width*map.pos.voxelSize or max[0] < map.pos.wx) return;
if(min[1] >= map.pos.wy +% CaveMapFragment.height*map.pos.voxelSize or max[1] < map.pos.wy) return;
@ -146,15 +146,15 @@ fn generateCaveBetween(_seed: u64, map: *CaveMapFragment, startWorldPos: Vec3d,
if(distance < @as(f64, @floatFromInt(map.pos.voxelSize))) {
generateSphere(&seed, map, startWorldPos, startRadius);
} else { // Otherwise go to the next fractal level:
const mid = (startWorldPos + endWorldPos)/@splat(3, @as(f64, 2)) + @splat(3, maxFractalShift)*Vec3d{
const mid = (startWorldPos + endWorldPos)/@as(Vec3d, @splat(2)) + @as(Vec3d, @splat(maxFractalShift))*Vec3d{
@floatCast(random.nextFloatSigned(&seed)),
@floatCast(random.nextFloatSigned(&seed)),
@floatCast(random.nextFloatSigned(&seed)),
} + bias/@splat(3, @as(f64, 4));
} + bias/@as(Vec3d, @splat(4));
var midRadius = (startRadius + endRadius)/2 + maxFractalShift*@as(f64, @floatCast(random.nextFloatSigned(&seed)))*heightVariance;
midRadius = @max(midRadius, minRadius);
generateCaveBetween(random.nextInt(u64, &seed), map, startWorldPos, mid, bias/@splat(3, @as(f64, 4)), startRadius, midRadius, randomness);
generateCaveBetween(random.nextInt(u64, &seed), map, mid, endWorldPos, bias/@splat(3, @as(f64, 4)), midRadius, endRadius, randomness);
generateCaveBetween(random.nextInt(u64, &seed), map, startWorldPos, mid, bias/@as(Vec3d, @splat(4)), startRadius, midRadius, randomness);
generateCaveBetween(random.nextInt(u64, &seed), map, mid, endWorldPos, bias/@as(Vec3d, @splat(4)), midRadius, endRadius, randomness);
}
}
@ -175,7 +175,7 @@ fn generateBranchingCaveBetween(_seed: u64, map: *CaveMapFragment, startWorldPos
const distanceToSeedPoint = vec.length(startWorldPos - newEndPos);
// Reduce distance to avoid cutoffs:
if(distanceToSeedPoint > (range - 1)*chunkSize) {
newEndPos = vec.floatFromInt(f64, centerWorldPos) + (newEndPos - vec.floatFromInt(f64, centerWorldPos))*@splat(3, ((range - 1)*chunkSize)/distanceToSeedPoint);
newEndPos = vec.floatFromInt(f64, centerWorldPos) + (newEndPos - vec.floatFromInt(f64, centerWorldPos))*@as(Vec3d, @splat(((range - 1)*chunkSize)/distanceToSeedPoint));
}
const newStartRadius = (startRadius - minRadius)*@as(f64, @floatCast(random.nextFloat(&seed))) + minRadius;
const newBias = Vec3d {
@ -211,36 +211,36 @@ fn generateBranchingCaveBetween(_seed: u64, map: *CaveMapFragment, startWorldPos
const newBias1 = bias + Vec3d{offsetX, offsetY, offsetZ};
const newBias2 = bias - Vec3d{offsetX, offsetY, offsetZ};
const mid1 = startWorldPos*@splat(3, weight) + endWorldPos*@splat(3, 1 - weight) + @splat(3, maxFractalShift)*Vec3d{
const mid1 = startWorldPos*@as(Vec3d, @splat(weight)) + endWorldPos*@as(Vec3d, @splat(1 - weight)) + @as(Vec3d, @splat(maxFractalShift))*Vec3d{
@floatCast(random.nextFloatSigned(&seed)),
@floatCast(random.nextFloatSigned(&seed)),
@floatCast(random.nextFloatSigned(&seed)),
} + newBias1*@splat(3, weight*(1 - weight));
const mid2 = startWorldPos*@splat(3, weight) + endWorldPos*@splat(3, 1 - weight) + @splat(3, maxFractalShift)*Vec3d{
} + newBias1*@as(Vec3d, @splat(weight*(1 - weight)));
const mid2 = startWorldPos*@as(Vec3d, @splat(weight)) + endWorldPos*@as(Vec3d, @splat(1 - weight)) + @as(Vec3d, @splat(maxFractalShift))*Vec3d{
@floatCast(random.nextFloatSigned(&seed)),
@floatCast(random.nextFloatSigned(&seed)),
@floatCast(random.nextFloatSigned(&seed)),
} + newBias2*@splat(3, weight*(1 - weight));
} + newBias2*@as(Vec3d, @splat(weight*(1 - weight)));
var midRadius = @max(minRadius, (startRadius + endRadius)/2 + maxFractalShift*@as(f64, @floatCast(random.nextFloatSigned(&seed)))*heightVariance);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, startWorldPos, mid1, newBias1*@splat(3, w1), startRadius, midRadius, centerWorldPos, branchLength, randomness, isStart, false);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, mid1, endWorldPos, newBias1*@splat(3, w2), midRadius, endRadius, centerWorldPos, branchLength, randomness, false, isEnd);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, startWorldPos, mid1, newBias1*@as(Vec3d, @splat(w1)), startRadius, midRadius, centerWorldPos, branchLength, randomness, isStart, false);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, mid1, endWorldPos, newBias1*@as(Vec3d, @splat(w2)), midRadius, endRadius, centerWorldPos, branchLength, randomness, false, isEnd);
// Do some tweaking to the radius before making the second part:
const newStartRadius = (startRadius - minRadius)*@as(f64, @floatCast(random.nextFloat(&seed))) + minRadius;
const newEndRadius = (endRadius - minRadius)*@as(f64, @floatCast(random.nextFloat(&seed))) + minRadius;
midRadius = @max(minRadius, (newStartRadius + newEndRadius)/2 + maxFractalShift*@as(f64, @floatCast(random.nextFloatSigned(&seed)))*heightVariance);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, startWorldPos, mid2, newBias2*@splat(3, w1), newStartRadius, midRadius, centerWorldPos, branchLength, randomness, isStart, false);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, mid2, endWorldPos, newBias2*@splat(3, w2), midRadius, newEndRadius, centerWorldPos, branchLength, randomness, false, isEnd);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, startWorldPos, mid2, newBias2*@as(Vec3d, @splat(w1)), newStartRadius, midRadius, centerWorldPos, branchLength, randomness, isStart, false);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, mid2, endWorldPos, newBias2*@as(Vec3d, @splat(w2)), midRadius, newEndRadius, centerWorldPos, branchLength, randomness, false, isEnd);
return;
}
const mid = startWorldPos*@splat(3, weight) + endWorldPos*@splat(3, 1 - weight) + @splat(3, maxFractalShift)*Vec3d{
const mid = startWorldPos*@as(Vec3d, @splat(weight)) + endWorldPos*@as(Vec3d, @splat(1 - weight)) + @as(Vec3d, @splat(maxFractalShift))*Vec3d{
@floatCast(random.nextFloatSigned(&seed)),
@floatCast(random.nextFloatSigned(&seed)),
@floatCast(random.nextFloatSigned(&seed)),
} + bias*@splat(3, weight*(1 - weight));
} + bias*@as(Vec3d, @splat(weight*(1 - weight)));
const midRadius = @max(minRadius, (startRadius + endRadius)/2 + maxFractalShift*@as(f64, @floatCast(random.nextFloatSigned(&seed)))*heightVariance);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, startWorldPos, mid, bias*@splat(3, w1), startRadius, midRadius, centerWorldPos, branchLength, randomness, isStart, false);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, mid, endWorldPos, bias*@splat(3, w2), midRadius, endRadius, centerWorldPos, branchLength, randomness, false, isEnd);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, startWorldPos, mid, bias*@as(Vec3d, @splat(w1)), startRadius, midRadius, centerWorldPos, branchLength, randomness, isStart, false);
generateBranchingCaveBetween(random.nextInt(u64, &seed), map, mid, endWorldPos, bias*@as(Vec3d, @splat(w2)), midRadius, endRadius, centerWorldPos, branchLength, randomness, false, isEnd);
}

View File

@ -234,10 +234,10 @@ const GenerationStructure = struct {
}
fn drawCircleOnTheMap(map: Array2D(*const Biome), biome: *const Biome, wx: i32, wz: i32, width: u31, height: u31, pos: Vec2f) void {
const relPos = (pos - vec.floatFromInt(f32, Vec2i{wx, wz}))/@splat(2, @as(f32, terrain.SurfaceMap.MapFragment.biomeSize));
const relPos = (pos - vec.floatFromInt(f32, Vec2i{wx, wz}))/@as(Vec2f, @splat(terrain.SurfaceMap.MapFragment.biomeSize));
const relRadius = biome.radius/terrain.SurfaceMap.MapFragment.biomeSize;
const min = @floor(@max(Vec2f{0, 0}, relPos - @splat(2, relRadius)));
const max = @ceil(@min(vec.floatFromInt(f32, Vec2i{width, height})/@splat(2, @as(f32, terrain.SurfaceMap.MapFragment.biomeSize)), relPos + @splat(2, relRadius)));
const min = @floor(@max(Vec2f{0, 0}, relPos - @as(Vec2f, @splat(relRadius))));
const max = @ceil(@min(vec.floatFromInt(f32, Vec2i{width, height})/@as(Vec2f, @splat(terrain.SurfaceMap.MapFragment.biomeSize)), relPos + @as(Vec2f, @splat(relRadius))));
var x: f32 = min[0];
while(x < max[0]) : (x += 1) {
var z: f32 = min[1];
@ -270,7 +270,7 @@ const GenerationStructure = struct {
std.log.warn("SubBiome {s} of {s} is too big", .{subBiome.id, biome.biome.id});
maxCenterOffset = 0;
}
const point = biome.pos + random.nextPointInUnitCircle(&seed)*@splat(2, maxCenterOffset);
const point = biome.pos + random.nextPointInUnitCircle(&seed)*@as(Vec2f, @splat(maxCenterOffset));
drawCircleOnTheMap(map, subBiome, wx, wz, width, height, point);
try extraBiomes.append(.{
.biome = subBiome,

View File

@ -439,7 +439,7 @@ pub const ServerWorld = struct {
}
pub fn dropWithCooldown(self: *ServerWorld, stack: ItemStack, pos: Vec3d, dir: Vec3f, velocity: f32, pickupCooldown: u32) !void {
const vel = vec.floatCast(f64, dir*@splat(3, velocity));
const vel = vec.floatCast(f64, dir*@as(Vec3d, @splat(velocity)));
try self.itemDropManager.add(pos, vel, stack, server.updatesPerSec*900, pickupCooldown);
}

View File

@ -27,7 +27,7 @@ pub fn length(self: anytype) @typeInfo(@TypeOf(self)).Vector.child {
}
pub fn normalize(self: anytype) @TypeOf(self) {
return self/@splat(@typeInfo(@TypeOf(self)).Vector.len, length(self));
return self/@as(@TypeOf(self), @splat(length(self)));
}
pub fn intFromFloat(comptime DestType: type, self: anytype) @Vector(@typeInfo(@TypeOf(self)).Vector.len, DestType) { // TODO: Remove once @floatToInt supports vectors.