67 Commits

Author SHA1 Message Date
Dylan K. Taylor
ee26d6d570
LightUpdate: avoid trying to propagate light into nodes with higher light levels
Track which direction the current node's light came from, and don't
check it again when we check the current node's adjacent blocks.

e.g. if this node was the eastern neighbour of a light source, we don't
need to check this node's western neighbour, as we already know it has
a higher light level than our own.

This improves performance of basic light spread in a void by about 6%,
which isn't a huge amount, but it's something.

I've yet to explore whether light removal could also benefit from this
change.
2023-10-09 17:06:02 +01:00
Dylan K. Taylor
6ac45526f9
Use new features in pocketmine/math 1.0.0 2023-08-03 16:46:16 +01:00
Dylan K. Taylor
d0d263191d
Fix build 2023-05-02 14:21:33 +01:00
Dylan K. Taylor
3366e1084b
LightUpdate: squeeze 10-15% more performance out of propagation
we can use SubChunkExplorerStatus to decide whether or not to update the local light array reference.

We also dereference some properties into local variables, because dereferencing properties is slow. Indirect property dereferences add an extra performance penalty for every layer.
2023-05-02 14:05:55 +01:00
Dylan K. Taylor
d0b9234841
SkyLightUpdate: deal with effective light during initial node discovery
this allows the propagation stage to ignore effective light, which allows for further optimisations.
2023-05-01 22:29:31 +01:00
Dylan K. Taylor
0a3ecfdae9
Clean up terminology around block state IDs and their handling 2023-01-25 19:01:15 +00:00
Dylan K. Taylor
4d79aced07
Merge branch 'next-minor' into next-major 2022-12-15 19:50:27 +00:00
Dylan K. Taylor
99996b62d6
Align PhpDoc @param tags according to PHP-CS-Fixer 2022-12-06 13:21:20 +00:00
Dylan K. Taylor
1ff69136a3
Merge branch 'next-major' into modern-world-support 2022-06-07 20:01:40 +01:00
Dylan K. Taylor
aa9f8781ff
Merge branch 'next-minor' into next-major 2022-06-07 19:56:26 +01:00
Dylan K. Taylor
dab7686656
Merge branch 'next-major' into modern-world-support 2022-06-04 18:43:11 +01:00
Dylan K. Taylor
083a35f970
Modernize property type declarations 2022-06-04 18:16:32 +01:00
Dylan K. Taylor
38d6284671
Use PHP-CS-Fixer to enforce file header presence 2022-06-04 17:34:49 +01:00
Dylan K. Taylor
03c505aaa7
Merge branch 'next-major' into modern-world-support 2022-05-22 16:21:48 +01:00
Dylan K. Taylor
179cac45f5
Merge branch 'stable' into next-minor 2022-05-22 16:21:05 +01:00
Dylan K. Taylor
01b0742bd4
LightUpdate: account for virtual nodes in prepareNodes()
fixes #3959
2022-05-21 17:07:49 +01:00
Dylan K. Taylor
68491be847
Merge branch 'next-major' into modern-world-support 2022-05-20 11:21:35 +01:00
Dylan K. Taylor
df3a69dcb7
Modernize private property declarations in Threaded classes
I previously avoided this due to being unsure of the effects; however, it's clear that we already use typed properties on Threaded things in other places anyway, and the only known issues are with uninit properties, and arrays.
2022-05-17 22:42:18 +01:00
Dylan K. Taylor
0326c4964b
Merge branch 'next-major' into modern-world-support 2022-04-28 21:06:44 +01:00
Dylan K. Taylor
b88a47929f
Modernize property declarations in src/world/* 2022-04-28 15:06:17 +01:00
Dylan K. Taylor
334c9daa6a
BlockFactory: change property cache arrays to use regular arrays instead of SplFixedArray
this does come at a performance cost, but is necessary for metadata expansion.

we finally concede that this is not going to happen without BC breaks, however small they might be ...
2022-03-23 15:22:57 +00:00
Dylan K. Taylor
aae5962f6a
Replace disallowed operators in src/world/ 2022-01-20 19:05:23 +00:00
Dylan K. Taylor
a6f6b60bed
fix CS again 2021-11-08 18:02:24 +00:00
Dylan K. Taylor
c6c992a1f0
Preparations for negative Y support 2021-11-08 17:28:22 +00:00
Dylan K. Taylor
8de30e8162
FastChunkSerializer no longer serializes light by default
the core doesn't use this anywhere.
serializeWithoutLight() has been renamed to serializeTerrain() to more accurately describe what it does.
2021-10-01 22:57:22 +01:00
Dylan K. Taylor
e6f6a036ef
LightPopulationTask: do not copy existing light arrays
this task wipes out the light arrays and recalculates them from scratch, so it's pointless to copy any preexisting light arrays anyway.
2021-10-01 22:34:11 +01:00
Dylan K. Taylor
5b818827db
Chunk: stop exposing SplFixedArray<SubChunk> to the API
this fixes a large number of PHPStan errors, and also brings us a step closer to negative-build-height readiness.
2021-10-01 22:17:28 +01:00
Dylan T
4111d92b98
Stop hardcoding chunk dimensions everywhere (#4443) 2021-09-10 16:13:25 +01:00
Dylan K. Taylor
22c3736d63
LightUpdate: micro optimisations opcache isn't smart enough for
this removes 6 unnecessary opcodes from computeSpreadLight() and 3 from computeRemoveLight(). Tested with opcache.opt_debug_level=0x20000.
2021-07-30 23:30:28 +01:00
Dylan K. Taylor
f1583f44df
LightArray: Avoid allocating 7 useless arrays for every node processed
instead, use a const array of the offsets and add them to the coordinates, which avoids the allocations.
In synthetic benchmarks, this method takes 40-50% less CPU time by eliding ZEND_INIT_ARRAY and ZEND_ADD_ARRAY opcodes. In practice, the benefit will likely be much smaller (perhaps even irrelevant).
2021-06-17 22:21:58 +01:00
Dylan K. Taylor
b31b097b8e
LightPopulationTask no longer hard-depends on Server 2021-04-16 15:41:14 +01:00
Dylan K. Taylor
eb9a68edee
Further refactors to prepare for y=-64 lower limit 2021-03-18 00:08:16 +00:00
Dylan K. Taylor
c808095978 Chunks no longer contain their own coordinates 2020-12-03 21:59:30 +00:00
Dylan K. Taylor
1f5998d24c FastChunkSerializer no longer encodes chunk coordinates
in cases like PopulationTask it makes more sense to store the coordinates separately where they can be stored more efficiently (once instead of 9 times)
In addition, PopulationTask shouldn't need to serialize an empty chunk just to copy coordinates.

I've made changes like this in other areas already in preparation for the day when chunks no longer contain their coordinates, so this brings us one step closer to that goal.
2020-12-03 20:52:33 +00:00
Dylan K. Taylor
5b1fa25dff LightPopulationTask: remove useless @var 2020-12-03 20:29:41 +00:00
Dylan K. Taylor
817372c55b SkyLightUpdate: make heightmap calculation routines pure 2020-10-31 23:42:32 +00:00
Dylan K. Taylor
c39a1407a2 Move heightmap calculation logic to SkyLightUpdate 2020-10-31 23:34:04 +00:00
Dylan K. Taylor
4549522289 Rename Chunk::getSubChunkChecked() -> getSubChunk() 2020-10-31 23:12:03 +00:00
Dylan K. Taylor
b270029161 Rename Chunk::getWritableSubChunk() -> Chunk::getSubChunkChecked()
this is not specific to 'writable', it's just an opt-in to checked bounds so that an EmptySubChunk will never be received.
2020-10-31 22:46:33 +00:00
Dylan K. Taylor
ddda2d1e64 Remove $create parameter from ChunkManager::getChunk()
this restores SimpleChunkManager's behaviour to PM3, removing the need for GeneratorChunkManager (although I'm dubious whether SubChunkExplorer makes any sense in there any more now that we have morton in the mix).
2020-10-31 21:54:51 +00:00
Dylan K. Taylor
1859dac789 Implemented self-contained (pass 1) chunk relighting
this doesn't handle propagating light across chunk borders yet, since that's much more complex to implement.
2020-10-27 18:29:32 +00:00
Dylan K. Taylor
0ecd68e4a7 LightUpdate: remove premature optimisation which breaks when mass-update lighting is used
when setBlockSkyLightArray/setBlockLightArray was used, currentLightArray would retain a reference to the old light array, which would cause false readings if SubChunkExplorer didn't move away from that subchunk and back.
This causes a small degradation of performance, but I think it can be implemented differently anyway.
This also fixes #3816.
2020-10-27 18:01:31 +00:00
Dylan K. Taylor
31c2c3abb5 SubChunkExplorer::moveTo() now returns a status
this can be used by SubChunkExplorer subclasses to implement specialized logic.
2020-10-26 16:25:21 +00:00
Dylan K. Taylor
89cce4c749 performance: only calculate light for chunks inside ticking areas
this produces a major performance improvement for large render distances, and reduces the impact of lighting calculation to zero on servers which have random blockupdates turned off.
2020-09-26 13:13:12 +01:00
Dylan K. Taylor
ae9e931849 LightPopulationTask: Simplify check for chunk loading in onCompletion()
we have no business loading chunks here either, although the isChunkLoaded() check should prevent that from happening.
2020-09-20 13:44:02 +01:00
Dylan K. Taylor
5096741b29 World::getChunk() behaviour now matches that of a regular ChunkManager
Various bugs existed for a while with stuff using chunk managers instead of worlds when interacting with terrain due to a behavioural inconsistency between World::getChunk() (return from cache or load from disk), and SimpleChunkManager::getChunk() (return from cache only). This change brings the two in line.
World::getOrLoadChunk() has been added as a replacement, which has the same behaviour as the old getChunk() and also makes it more obvious that there is an issue with code using it during refactoring.
2020-09-20 13:29:09 +01:00
Dylan K. Taylor
c9d2edcb4d Rename SubChunkIteratorManager -> SubChunkExplorer 2020-09-20 12:47:44 +01:00
Dylan K. Taylor
4879df626d Reduced LightUpdate dependency on ChunkManager to indirect
this opens the gateway for alternative SubChunkIteratorManager implementations which don't use ChunkManager at all.
2020-09-20 12:41:53 +01:00
Dylan K. Taylor
c20ac82fe6 LightUpdate: Move propagation-specific state to a separate unit
this solves multiple architectural issues:
- improves reusability by avoiding having old state info stick around to fuck stuff up
- prevents access to propagation state from outside of propagation

this also reduces the latent memory usage of light-updates after they have been used.

TODO: we could probably change LightPropagationContext to LightPropagator and move all the propagation-specific code into it if we can solve the subchunk-iterator and effective light problems.
2020-09-09 01:06:09 +01:00
Dylan K. Taylor
bde24d9279 LightUpdate: remove unused field 2020-09-08 23:14:10 +01:00