-
-
Notifications
You must be signed in to change notification settings - Fork 232
Client block random ticks #3396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6a6bba2
72f4c43
57bf8dd
f968396
c4cac11
cfd351c
ade1fe2
cc8589b
1ece600
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| .{ | ||
| .texture = "cubyz:flame", | ||
| .density = .{0.00065, 0.00085}, | ||
| .rotationVelocity = .{20, 35}, | ||
| .rotationVelocity = .{5, 10}, | ||
| .dragCoefficient = .{0.2, 0.3}, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub const edit_sign = @import("edit_sign.zig"); | ||
| pub const open_chest = @import("open_chest.zig"); | ||
| pub const open_window = @import("open_window.zig"); | ||
| pub const torch_update_particles = @import("torch_update_particles.zig"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| const std = @import("std"); | ||
|
|
||
| const main = @import("main"); | ||
| const Block = main.blocks.Block; | ||
| const vec = main.vec; | ||
| const Vec3i = vec.Vec3i; | ||
| const ZonElement = main.ZonElement; | ||
| const particles = main.particles; | ||
|
|
||
| pub fn init(_: ZonElement, _: main.callbacks.Creator) ?*anyopaque { | ||
| return @as(*anyopaque, undefined); | ||
| } | ||
|
|
||
| pub fn run(_: *anyopaque, params: main.callbacks.ClientBlockCallback.Params) main.callbacks.Result { | ||
| var emitter: particles.Emitter = undefined; | ||
| const emitterProperties = particles.EmitterProperties{ | ||
| .speed = .init(0.15, 0.2), | ||
| .lifeTime = .init(0.25, 0.5), | ||
| .randomizeRotation = false, | ||
| }; | ||
| emitter = .init("cubyz:flame", false, .{.point = .{}}, emitterProperties, .spread); | ||
| emitter.spawnParticles(@as(vec.Vec3f, @floatFromInt(params.blockPos)) + vec.Vec3f{0.5, 0.5, 0.85}, 1); | ||
| return .handled; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -281,6 +281,7 @@ pub const World = struct { // MARK: World | |||||
| entityComponentPalette: *assets.Palette = undefined, | ||||||
| itemDrops: ClientItemDropManager = undefined, | ||||||
| playerBiome: Atomic(*const main.server.terrain.biomes.Biome) = undefined, | ||||||
| randomTicksTime: f64 = 0, | ||||||
|
|
||||||
| shouldRestart: std.atomic.Value(bool) = .init(false), | ||||||
| shouldReload: bool = false, | ||||||
|
|
@@ -412,6 +413,36 @@ pub const World = struct { // MARK: World | |||||
| } | ||||||
| network.protocols.playerPosition.send(self.conn, Player.getPosBlocking(), Player.getVelBlocking(), @intCast(newTime & 65535)); | ||||||
| self.dayTime.update(deltaTime); | ||||||
|
|
||||||
| self.randomTicksTime += deltaTime; | ||||||
| const tickrate: f32 = 1.0/20.0; | ||||||
| if (self.randomTicksTime >= tickrate) { | ||||||
| updateRandomTickBlocks(self); | ||||||
| self.randomTicksTime = 0; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn updateRandomTickBlocks(_: *World) void { | ||||||
| const chunkRadius = settings.visualRandomTickRadius; | ||||||
| const playerBlockPos: Vec3i = @intFromFloat(@floor(Player.getPosBlocking())); | ||||||
| const thing: i32 = @intCast(if (@mod(chunkRadius, 2) == 0) @divFloor(chunkRadius, 2) else @divFloor(chunkRadius - 1, 2)); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a radius if you half it |
||||||
| for (0..chunkRadius) |cx| { | ||||||
| for (0..chunkRadius) |cy| { | ||||||
| for (0..chunkRadius) |cz| { | ||||||
| const chunkMultiplierPos: Vec3i = playerBlockPos +% @as(Vec3i, @splat(32))*Vec3i{@as(i32, @intCast(cx)) - thing, @as(i32, @intCast(cy)) - thing, @as(i32, @intCast(cz)) - thing}; | ||||||
| const chunkMesh = main.renderer.mesh_storage.getMesh(.initFromWorldPos(chunkMultiplierPos, 1)); | ||||||
|
|
||||||
| if (chunkMesh) |mesh| { | ||||||
| for (0..20) |_| { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be configurable |
||||||
| const curBlockPos = Vec3i{main.random.nextIntBounded(i32, &main.seed, 32), main.random.nextIntBounded(i32, &main.seed, 32), main.random.nextIntBounded(i32, &main.seed, 32)}; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can create a random BlockPos directly from a |
||||||
| const block = mesh.chunk.getBlock(curBlockPos[0], curBlockPos[1], curBlockPos[2]); | ||||||
| const onClientUpdate = block.onClientUpdate(); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| if (onClientUpdate.run(.{.blockPos = curBlockPos + Vec3i{mesh.pos.wx, mesh.pos.wy, mesh.pos.wz}, .block = block, .chunk = mesh.chunk}) == .handled) continue; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub const DayTime = struct { // MARK: DayTime | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To catch lag spikes, this should be a while loop, below it should subtract the tickRate instead of setting it to 0