33 Commits

Author SHA1 Message Date
Krzysztof Wiśniewski
64ce0ed991
Batch block updates (#1313)
* Batch block updates

* Apply review change requests

* Allow blockUpdate to carry multiple block updates in single message

* Read until there is nothing left

* Use mesh_storage.BlockUpdate

* Break instead of boolean

* Restore client side neighbor updates

* Move side check in blockUpdate out of the loop

* Update src/utils.zig

* Fix minor issues

* Reverse ownership logic + change contains into liesInChunk

* Update liesInChunk

* No name for upadeBlock param

* Apply review change requests

* Fix formatting

* Restore onBreakClient where it should be

* Update src/renderer/chunk_meshing.zig

* Update src/renderer/chunk_meshing.zig

* Converge formatting with master

* fix formatting (https://github.com/ziglang/zig-spec/issues/38 is so stupid)

---------

Co-authored-by: IntegratedQuantum <jahe788@gmail.com>
2025-05-01 10:10:03 +02:00
IntegratedQuantum
5f54d48a73
The new network system (#1297)
* Create the foundations of the new network system.

* Fix memory leak

* Implement a simple additive-increase-multiplicative-decrease congestion control scheme.

Also fixed the locking with the send path

* Fix edge case for mismatch in read and available position

* fix formatting

* Reimplemtent network statistics of the F6 menu

* Fix problem the F6 window size

* Rename size to capacity

* Implement the advanced network debug menu

* Fix a few problems

* Actually call the handlePacketLoss function

* Reduce startup delay and fix possible problems with negative RTTs

* Fix crash in block of partially received packets.

* Use a PriorityQueue for unconfirmed packets.

Also fixed a display issue in the advanced network menu

* Always send confirmations and change how packet loss is handled to avoid killing the network connection by only resending packets outside the receive buffer.

* Use the length instead of the endIndex in the CircularBufferQueue

this just made everything more difficult to work with.

* Optimize CircularBufferQueue.enqueueSlice with memcpy

* Fix problem with zero-length packets, which is a valid use case

* Fix a small edge case

* fix formatting

* Add missing code to increase the capacity in enqueueSlice

* Don't send more data than the receive buffer can fit.

* Use a better data structures that handles the received ranges

* Use memcpy in more circular buffer functions

* Send a keepalive if the connection hasn't been established but the player was invited by the server

* Implement disconnecting for the new protocol

* Reimplement timeout

* Only add new connections when the other side actually sent an init packet.

otherwise the connections stay in the queue, and need keepalives.

also moved the code from the invite window to network.zig, where it belongs

* Don't allow queueing more than 2 GiB of data (i32 limit)

* Reimplement and simplify reconnection

* Use member functions for Socket

* React to packets using a scheme similar to TCP

TCP will send a fast retransmit on first loss discovered by DACKs, shortly after starting the RTO timer.
In essence this means that only second loss of the smallest packets is handled by congestion control.

* Increase scaling after congestion control halves bandwidth.

Now it increases it by at least 1%, isntead of only by the MTU

* Use start and len instead of start and end for the RangeBuffer

* Use ListUnmanaged in RangeBuffer

* Rename flawedReceive to tryReceive

* Add a `ms` constant to make it easier to see what units some of the constants use.

Also added a function alias for microTimestamp to make it potentially easier to change to other timestamps in the future.
2025-04-19 15:05:02 +02:00
IntegratedQuantum
c2ef9aba62 Remove the root . . . . . . . . . . import, replacing it with @import("main")
To fully solve the ZLS issues I had to also add the import to the other executables.
2025-03-27 21:16:35 +01:00
IntegratedQuantum
01cfb786aa Use a dedicated ModelIndex and QuadIndex to make more clear what it is and how to use it.
I also bumped model index size to 32 bits (storage is currently limited to 20 bits though)
We can afford this, since it's CPU side and it's only stored perblock type.
2025-03-22 10:45:09 +01:00
IntegratedQuantum
50de67fca1 Introduce our own MemoryPool type for easier locking, more diagnostics and safety. 2025-03-09 17:32:55 +01:00
IntegratedQuantum
03769c2cda
Update Zig to 0.14.0 (#1158)
* Update Zig to 0.14.0

* Update ci.yml

* Copy the zig fmt source code

* Update ci.yml

* Fix formatting issues

* Update CONTRIBUTING.md with a new formatting command
2025-03-05 21:41:02 +01:00
IntegratedQuantum
bc02bb0587
Use (an adapted version) of zig fmt to format the source code. (#1140)
* Format all the files

* Fix compilation error.

* The install scripts now patch render.zig from the zig standard library.

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update the formatter, it doesn't need to run on .zig files anymore.

* Update ci.yml

* Update ci.yml

* Add a mistake to check if it works

* IT WORKS!
2025-03-02 16:36:58 +01:00
IntegratedQuantum
59cbde3f03 Don't propagate sunlight from light emitting blocks.
Previously there was a (mostly invisible) layer of sunlight being emitted around every block.

fixes #880 and should also make light propagation on placing blocks faster.
2025-01-02 16:08:02 +01:00
IntegratedQuantum
72207c973e Refactor: Use decl literals, a recent addition to Zig. 2024-09-14 14:54:49 +02:00
IntegratedQuantum
2d359ccb86 Turn chunk.Neighbors into an enum.
Syntactically this seems to be a pretty neutral change, some expression get longer, other get shorter.
But I guess it increases type safety and I could also replace some of the more magic operations, like `neighbor ^ 1` with a named function.

fixes #602
2024-08-03 17:21:20 +02:00
IntegratedQuantum
ff80474943 Consider the emissive light of blocks during destructive light updates.
fixes #530
2024-06-28 10:06:24 +02:00
IntegratedQuantum
04f9bae91c Remove redundant light refreshes.
helps with #277
2024-06-27 22:49:22 +02:00
IntegratedQuantum
6e241b9258 Use a read-write lock with read-priority for light data.
fixes #331
helps with #277
2024-06-26 15:53:14 +02:00
IntegratedQuantum
cb2c7f07c3 Add a fast-path for sunlight propagation in uniform air chunks.
fixes #320, terrain generation in single-player is now ~30% faster.
2024-06-04 14:20:25 +02:00
IntegratedQuantum
c64ece2163 Revert 413372a3218d966f328d09b11f2b4966ea91c357
RwLocks don't work like that.
Fixes #330
2024-04-23 22:45:56 +02:00
IntegratedQuantum
775dcc85fc Use palette compression for chunks and increase the maximum render distance.
fixes #156
fixes #136
2024-04-17 17:29:25 +02:00
IntegratedQuantum
64e37dca26 Move all the palette compression related code into utils.
More progress towards #156
2024-04-17 16:22:27 +02:00
IntegratedQuantum
82be61ed6d Implement mutex assertions only in debug mode.
This avoids side effects in release fixing #317
2024-04-16 22:16:19 +02:00
IntegratedQuantum
413372a321 Use a RwLock for the lighting data to allow meshing to lock it in a wider scope.
Fixes #319
2024-04-14 20:20:17 +02:00
IntegratedQuantum
86e08b9f8a Use palette compression for light data, reduing memory usage (of light data) by up to 100×.
Progress towards #156
Makes #277 worse
2024-04-14 15:42:49 +02:00
IntegratedQuantum
0acb0e2c80 Update zig
This one was annoying.
2024-04-03 13:57:38 +02:00
IntegratedQuantum
5fea779e37 Undo the performance regression of the previous commit by adding a special case for air blocks. 2024-03-30 22:54:48 +01:00
IntegratedQuantum
4ab40cc85b Better occlusion and lighting for non-cube models.
Full faces of non-cube models now block light and occlude neighbor faces, whereas the others will let light through.
This does make light propapagation significantly (~40%) slower though due to the extra logic involved.

Closes #295
2024-03-30 22:13:55 +01:00
IntegratedQuantum
8418202df8 Store and update 3 color channels at once instead of treating them all seperately. This makes lighting ~twice as fast. 2024-03-26 21:23:21 +01:00
IntegratedQuantum
69920c343d Don't access the internals of the ChannelChunk.
This makes it easier to swap the implementation for future compression attempts.
2024-02-26 14:59:00 +01:00
IntegratedQuantum
d08096057f Improve the StackAllocator so it allows all kinds of allocation patterns.
This allows using the StackAllocator for more data structures and library functions.
Fixes #268
Fixes #95 (at least to the point where I can't do anything about it)
2024-02-08 18:01:43 +01:00
IntegratedQuantum
0177099f6b Reduce GPA usage in lighting.zig to improve CPU usage. It's now close to 90%. 2024-02-07 19:00:16 +01:00
IntegratedQuantum
534ca665cb Improve thread utilization from ~40% to ~70%
This is done by reusing the lightQueue instead of allocating new ones(→less locking in the allocator) and by avoiding too frequent task priority updates(→less locking when adding new tasks).
The remaining 30% will hopefully be done by improvements to the zig GPA.
2024-02-07 13:16:20 +01:00
IntegratedQuantum
acd777bf13 Improve light propagation by not walking back in the direction that it came from.
Should be about a 16% improvement and a reduction in scheduled mesh updates.
2024-02-07 11:33:28 +01:00
IntegratedQuantum
781ca89aff Use MemoryPool for chunk and lighting data.
Temporarily fixes #263
2024-02-05 21:33:56 +01:00
IntegratedQuantum
2c33f3779d Switch to a self-made list data structure that doesn't return OutOfMemory errors. 2024-01-30 16:34:40 +01:00
IntegratedQuantum
de004841b7 Handle OutOfMemory errors centrally for the globalAllocator and derivatives.
To let the rest of the code know about this decision I implemented a wrapper over the Allocator interface which cannot fail.

This is just the first step in the upcoming refactoring attempt.
2024-01-29 17:22:20 +01:00
IntegratedQuantum
25e4ba6b84 Split up chunk.zig and renderer.zig
I'm getting tired of scrolling around in those large files.
2024-01-15 18:55:33 +01:00