85 Commits

Author SHA1 Message Date
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
0dc0da90d8 Fix formatting issues. 2025-03-05 19:22:53 +01:00
IntegratedQuantum
f3b508bf47 Introduce a BinaryReader/Writer to make working with binary protocols easier especially with regards to error handling.
fixes #762
fixes #264
2025-03-05 19:14:49 +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
22488a28ae CI: Check for trailing spaces and (missing) newlines at the end of the file
fixes #737
2025-02-12 17:36:44 +01:00
IntegratedQuantum
36c38dca2d Show an error prompt every time there is an error message added to the log.
This should make it easier to find and fix problems in the assets.

fixes #911
2025-01-12 16:41:32 +01:00
OneAvargeCoder193
5986c76c45
Add player and inventory saving (#878)
* Save the player's location and inventory, and also added the ability to load the player's location

* remove the comment from utils

* make the player save every 5 seconds

* fix gamemode loading

* remove comment

* added inventory loading

* fix bug

* fix unintentional changes

* fix segfault

* fixes

* Some small fixes.

---------

Co-authored-by: IntegratedQuantum <jahe788@gmail.com>
2025-01-02 15:14:22 +01:00
IntegratedQuantum
de90b4ede3 Introduce a ConcurrentQueue to reduce the number of raw mutexes used throughout the code to simplify the code reduce the chance of (multithreaded) deadlocks.
For now it's just a queue with a mutex.

this might help with #863 and #864 in the future.
2024-12-30 00:59:45 +01:00
IntegratedQuantum
c978afab50 Fix assertion failures with the arena.shrinkAndFree function. 2024-12-06 22:22:25 +01:00
IntegratedQuantum
fd478e2b99 Add a shrinkAndFree method to the Arena to reduce memory footprint of StructureMapFragments by ~20%
progress towards #813
2024-12-05 21:47:16 +01:00
IntegratedQuantum
7651ae6aee Change how visible meshes are determined and traversed.
I gave up on two restrictions:
1. low-to-high LOD borders are no longer prevented. This was only a problem for low render distance + fast movement, and the consequences of the fix were causing flickering in some cases, and to be honest I prefer small gaps in the terrain.
2. 2×2×2 chunks are grouped and rendered together. This makes the vertex shader a bit simpler and allows hierarchical traversal of chunks. However this means that the minimume render distance had to be increased again.

Overall this gave around a 30% reduction in CPU time for selecting the visible chunks. This also reduced jitter during loading.

makes #722 less severe
would make #745 more effective

Further optimizations might be possible.
2024-11-30 15:23:40 +01:00
IntegratedQuantum
60b91bfdb8 Prevent the game from opening multiple instances of region files.
Also made the ThreadPool task count more accurate.

fixes #770
2024-11-12 22:23:54 +01:00
IntegratedQuantum
13974d12ab Fix crash from not initializing the Performance info struct of the ThreadPool. 2024-10-27 21:34:29 +01:00
IntegratedQuantum
08b7549f2a Use more concise file API functions from the standard library. 2024-10-21 17:08:50 +02:00
archbirdplus
6b1e5ee5ce
Show task performance (#445)
* threadpool: track and show task times

* debug window: subdivide task performance

* indent debug window code

* task perfs: remove meshgen for lighting

* task perfs: don't divide by zero

* task perf: move taskType to vtable

* use directEnumArrayLen instead of C-style length

* use @tagName for task type classes

* switch to atomics

* recategorize LightRefreshTaks, LightMapLoadTask under misc

* add frameCount

* update perfs every perfUpdateFrequency frames

* restore 4k pageSize

* lighting -> meshgenAndLighting

* reset counts on open rather than by time

* revert to mutex Performance

* restore 4096 pageSize

* cleanup

* correctly use Performance init

* track task time per frame properly

* just copy.*

* use % total instead of % frame time

* capitalize Total task time

* remove total task time

* destroy performance on deinit
2024-10-21 16:13:32 +02:00
IntegratedQuantum
b710ccad07 Squeeze all inventory operations through a simple structure that allows undoing operations.
more progress towards #643
This is the client-side prediction part of the client-server architecture.
2024-10-18 22:17:47 +02:00
IntegratedQuantum
e863e9f311 Remove unused milliTime parameter from the threadpool task vtable. 2024-10-07 20:28:48 +02:00
IntegratedQuantum
c863d676b5 Improve chunk compression on file/network by running deflate on an 8 bit palette compressed chunk instead of the raw data.
Decreases compressed chunk size by ~30%, should also greatly improve compression/decompression times.

fixes #326
2024-10-06 17:07:57 +02:00
IntegratedQuantum
72207c973e Refactor: Use decl literals, a recent addition to Zig. 2024-09-14 14:54:49 +02:00
IntegratedQuantum
330187b9ae Update zig version 2024-09-14 13:42:25 +02:00
IntegratedQuantum
e49353aad9 Reduce locking in the ThreadPool to avoid locking while calling any task related functions.
fixes a deadlock and reduces the chance for future deadlocks of this kind.
should also fix #384 since now the largest continuous locking time is shorter.
2024-08-29 15:16:06 +02:00
IntegratedQuantum
47356faa23 Fix some item drop physics and visuals.
It uses 4 collision checks to ensure that the item drop doesn't fall through blocks.
Jittering is fixed by adding the acceleration before the collision test.
items are now larger than blocks
items are now centered.
2024-08-18 18:49:51 +02:00
IntegratedQuantum
4fa08bec95 Add the ability to insert ranges of equal blocks into the palette compressed data structure.
The index is then only calculated once. Individual insertions are not optimized though.

fixes #600

Also it seems that in my previous performance commit I had made a mistake in my measurement, I must have measured a buggy version which turned out to be super fast. In actuality the performance difference was much smaller, so I decided to optimize that section as well.

Now it's at 1.7 ms per chunk. Still needs more improvements, I guess.
2024-08-01 17:30:44 +02:00
IntegratedQuantum
cde841bc6a Improve performance of PaletteCompressedRegion.setValue.
That made it almost 2× faster. But it's only a ~4% improvement of the total terrain generation time.
2024-07-30 10:11:29 +02:00
IntegratedQuantum
daf2f0332e Remove some deprecated APIs to become compatible with the latest master zig. 2024-07-18 21:09:32 +02:00
IntegratedQuantum
289e3c61f1 Add VSCode section headers to make navigating large files easier. 2024-07-14 11:31:57 +02:00
IntegratedQuantum
5f192f224f Decrease the compression ratio of stored maps to improve their generation time.
helps with #513
2024-07-01 16:36:54 +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
843512eae6 Add Congestion control to the network protocol.
Packets are now sent more evenly spaces to avoid congestion on the send buffer of the operating system.

Expensive protocols, like the chunkTransmission protocol, are now executed in parallel to avoid congestion from unpacking large chunks of data in the network thread.

And finally the base protocol now tries to estimate the available bandwidth of the connection based on data of last 1.6 seconds (sorry to the people who live on the moon, your bandwidth cannot be estimated and is set to 100000 kB/s, so you will have trouble playing with your friends on earth).

fixes #216
fixes #212
2024-05-23 18:00:17 +02:00
IntegratedQuantum
6f2973e440 Add the invite screen and fix a few small issues.
Progress for #100
2024-05-19 12:57:39 +02:00
IntegratedQuantum
001416dde6 Refactor the Chunk, sperating the Server-specific functionality into a new struct.
Also fixes some data races and changes the default compression so it no longer includes the (redundant) chunk position.
2024-05-17 17:28:53 +02:00
IntegratedQuantum
2295ddf310 Fix compiler error on windows after update. 2024-05-14 09:45:30 +02:00
IntegratedQuantum
3e0c666108 Audit usage of reference counting, making it thread safe in a (pretty rare) edge case.
Also uses a more consistent naming convention when reference counting is involved.

Fixes #332
Potentially fixes #329 (I can't reproduce it anymore)
Discovers #338
2024-04-30 22:36:46 +02:00
IntegratedQuantum
c9f9dbf634 Avoid unnecessary syscalls from checking the millitime in each call of isStillNeeded
Reduces lag caused by updating the priorities in the threadpool.
2024-04-18 17:02:19 +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
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
2dfbe98844 Add texture hot-reloading for Linux and Windows.
Closes #106
2024-04-02 16:47:32 +02:00
IntegratedQuantum
3ae9921de8 Update Zig 2024-03-03 13:14:18 +01:00
IntegratedQuantum
1cc6410ef6 z is now up
Closes #272
2024-02-26 17:31:42 +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
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
451cac2923 Use a CircularBufferQueue for lighting instead of a PriorityQueue.
A CircularBufferQueue means that we might revisit some points, for example when there is a dim and a bright light source.
However in practice the performance impact of using a PriorityQueue is huge, so this edge case doesn't matter really.

This makes light propagation about 20 times faster and should help with #223, but it doesn't seem to actually make a difference. There is likely something else going on here.
2023-12-07 16:58:50 +01:00
IntegratedQuantum
a61fe26fab Update zig: Andrew broke it all. 2023-11-28 00:04:01 +01:00
IntegratedQuantum
c1c6aa7138 Further improve allocator usage in the network thread.
This finally fixes #171 (although CPUs with even more threads, or a future game with even better optimized terrain generation will still have this problem)
2023-11-21 22:19:52 +01:00