123 Commits

Author SHA1 Message Date
Dylan K. Taylor
ec2feeffcb World->populateChunk() no longer causes ChunkLoadEvent to fire with an empty chunk
instead, it will fire when the chunk comes out of PopulationTask and is set into the world using setChunk().
There is still one place left where auto-creation of empty chunks is used by the core, and that's an issue i'm still deciding how to deal with.
2020-12-03 18:23:03 +00:00
Dylan K. Taylor
fa9be2477d World: do not fire ChunkListener->onChunkChanged() when a new chunk is set
the documentation expressly describes a chunk being _replaced_ by a new chunk. This doesn't fit when the chunk didn't exist to begin with.
2020-12-03 18:20:43 +00:00
Dylan K. Taylor
74744fd498 World: fire ChunkLoadEvent in setChunk() if the chunk did not previously exist
I'm of two minds whether this should continue to fire onChunkChanged() on chunk loaders or not, since the chunks won't be referenced by any chunk loader anyway by virtue of not existing ...
2020-12-03 18:15:09 +00:00
Dylan K. Taylor
10067c1043 Improve painting performance
these really shouldn't hit the CPU at all considering they are simply static objects ...
2020-12-01 23:31:38 +00:00
Dylan K. Taylor
4ea5401d72 World->getHighestBlockAt() now throws an exception instead of returning -1 in ungenerated terrain 2020-11-26 19:44:22 +00:00
Dylan K. Taylor
fd99445c5b World->getSafeSpawn() now throws if the target is in ungenerated terrain, instead of silently returning the default
this WILL cause crashes in some cases on slower machines (#2724), but it's
better than randomly spawning at the top of the map.
2020-11-26 19:36:37 +00:00
Dylan K. Taylor
6cf875ca3a Item: rename onActivate() to onInteractBlock() 2020-11-09 19:33:13 +00:00
Dylan K. Taylor
66955d4b99 World: make loadChunk() more useful, drop useless proxy function getOrLoadChunk() 2020-11-09 13:41:46 +00:00
Dylan K. Taylor
64afb6f2e2 Move responsibility of firing chunk requests from World to NetworkSession
this is, after all, all about sending chunks ...
2020-11-08 14:14:43 +00:00
Dylan K. Taylor
4b46549cd1 fix PHPStan failure
setDirtyFlag has a void return type, so PHPStan assumes it's non-pure and invalidates the type info.
2020-11-05 14:35:23 +00:00
Dylan K. Taylor
058a3b3fa6 relocate some world-specific logic from Chunk to World 2020-11-05 14:28:36 +00:00
Dylan K. Taylor
8762d44506 World: skip lighting updates on chunks which are not yet light populated 2020-11-04 17:50:16 +00:00
Dylan K. Taylor
5cc2a9c3dd World: rename getChunkAtPosition() to getOrLoadChunkAtPosition()
this more accurately reflects what it does.
2020-11-03 14:12:47 +00:00
Dylan K. Taylor
2e9b2d4aae World: fixed false unload events firing on chunk replacement when tiles and entities are deleted 2020-11-01 17:41:58 +00:00
Dylan K. Taylor
61112e4912 World: make create params of loadChunk and getOrLoadChunk mandatory
differences in the default values almost caused me to miss some bugs while trying to remove them.
2020-11-01 17:36:56 +00:00
Dylan K. Taylor
0bb37b5065 World: formalize setBlockAt()'s refusal to modify un-generated chunks
closes #2631
2020-11-01 17:24:09 +00:00
Dylan K. Taylor
1f2bc8cb69 World: remove rogue import 2020-11-01 17:05:57 +00:00
Dylan K. Taylor
4231bfdc7e Relocate biome ID constants to pocketmine\data\bedrock package 2020-11-01 16:53:06 +00:00
Dylan K. Taylor
b176f4c12f Switch to BiomeRegistry
I accidentally committed this in c869a7f099237ca189dc574fe3df6e7630eeec51 and didn't notice. I intended to use it and never noticed.
2020-11-01 16:47:13 +00:00
Dylan K. Taylor
1d551af54a Merge remote-tracking branch 'origin/stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/level/Level.php
#	src/pocketmine/level/format/Chunk.php
#	tests/phpstan/configs/l7-baseline.neon
2020-11-01 15:58:16 +00:00
Dylan K. Taylor
2684ee96f7 World: do not perform base lighting calculation on non-generated chunks
this was causing twice as many light calculations for freshly generated chunks.
2020-11-01 15:53:50 +00:00
Dylan K. Taylor
ef542880de WorldManager: allow different World instances to have different AsyncPool instances
instead of being forced to use the Server async pool
right now the intent of this is to reduce (and ultimately eliminate) the dependency of World on Server, but it might come in useful for other stuff too, for example a chunkserver-based generator implementation which blocks on network instead of eating CPU (it would just waste CPU for other tasks).
2020-11-01 15:21:15 +00:00
Dylan K. Taylor
11434f3a27 World::setBiomeId() now bails when trying to modify a non-generated chunk (or chunk locked for generation) 2020-11-01 15:00:48 +00:00
Dylan K. Taylor
d6d9dde0b2 imports cleanup 2020-11-01 14:23:21 +00:00
Dylan K. Taylor
4549522289 Rename Chunk::getSubChunkChecked() -> getSubChunk() 2020-10-31 23:12:03 +00:00
Dylan K. Taylor
13d7b7ee1a Removed final remaining usages of Chunk::getSubChunk()
this clears the way to get rid of EmptySubChunk.
2020-10-31 23:07:36 +00:00
Dylan K. Taylor
bacfcf258e World: remove unused function 2020-10-31 23:00:27 +00:00
Dylan K. Taylor
5701e733cc World: fixed a crash in getFullBlock() when used on ungenerated terrain 2020-10-31 22:36:12 +00:00
Dylan K. Taylor
f5807ac049 World::getBlockAt() now doesn't assume that AIR has a fullStateId of 0 2020-10-31 22:22:02 +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
dec235abab World: don't create a new chunk just to read biome info
the chunk won't be generated, so we can provide the default result without creating a new chunk for no reason.
2020-10-31 21:29:39 +00:00
Dylan K. Taylor
de867f1b86 World: don't create an empty chunk just for accessing the highest block
this is pointless since the chunk will not be generated anyway, so it serves no end to create it.
2020-10-31 21:27:16 +00:00
Dylan K. Taylor
f0d62cf4ce World: don't try to load chunks to read light levels
sync chunk load is useless here because lighting isn't immediately calculated anyway and it isn't available directly from the chunk when loaded.
2020-10-31 20:38:15 +00:00
Dylan K. Taylor
5f7b0994b9 World: rename get(HighestAdjacent)BlockSkyLight(At) to make it clear these are **potentials**, not the actual light level 2020-10-31 16:47:34 +00:00
Dylan K. Taylor
241a50387b World: added getHighestAdjacentRealBlockSkyLight()
this is the same as its 'non-real' counterpart, but it accounts for time of day.
2020-10-31 16:44:42 +00:00
Dylan K. Taylor
66edf5a165 Particle::encode() now always returns ClientboundPacket[] 2020-10-31 15:51:17 +00:00
Dylan K. Taylor
5a320f22b7 Sound::encode() now always returns an array 2020-10-31 15:48:46 +00:00
Dylan K. Taylor
058bb3a91a World: do not execute neighbour block updates on unloaded chunks
we might also need to delay this if any adjacent chunk is also not loaded, in case the block wants to access adjacent blocks during its neighbour update.
2020-10-29 13:37:14 +00:00
Dylan K. Taylor
cfb9cc8999 fix build failure 2020-10-29 13:22:35 +00:00
Dylan K. Taylor
b079772d32 World: do not include unloaded or unlit chunks in getHighestAdjacentBlock(Sky)Light() 2020-10-29 13:05:25 +00:00
Dylan K. Taylor
3c892182fd World: change some usages of getOrLoadChunk() to getChunk()
these usages don't require getOrLoadChunk() because they already check for unloaded chunks anyway.
2020-10-29 12:57:33 +00:00
Dylan K. Taylor
3e1263eb79 Chunk: remove all proxy APIs to lighting information
these aren't used by internals and they shouldn't be used by plugins either.
2020-10-29 12:11:06 +00:00
Dylan K. Taylor
286ac2a975 Rework World::blockHash() to use morton3d
this uses the unused bits on the Y component to expand the X/Z axes to 2^27 blocks long instead of 2^21 permitted by a regular morton3d code. It does require the sacrifice of an additional bit on the Y axis, but the performance advantages are more than worth it.
I'm exploring how realistic it would be to just eliminate blockHash global usage (currently in lighting updates and explosions). This would allow scaling up to 2^32 without larger hashes (morton2d for chunks).
2020-10-20 20:31:10 +01:00
Dylan K. Taylor
0f9d5f7011 ext-morton is now required and used for World::chunkHash() and World::chunkBlockHash() 2020-10-17 16:09:30 +01:00
Dylan K. Taylor
eabfd2a37b World: replace sendBlocks() with createBlockUpdatePackets()
this allows the caller to decide how the packets should be sent.
2020-10-11 16:30:54 +01:00
Dylan K. Taylor
ca9f3020b4 World: added private broadcastPacketToPlayersUsingChunk()
this is equivalent to the old addChunkPacket, but private and with a less stupid name.
2020-10-11 15:21:15 +01:00
Dylan K. Taylor
a05b1fec7e World: rename chunkPackets -> packetBuffersByChunk 2020-10-11 15:18:57 +01:00
Dylan K. Taylor
bd3bf3d0ce Revert "World: do not group broadcasted packets by chunk, broadcast directly instead"
This reverts commit b172c93e45e60ee3dbfd8a2efbede60b894673a3.

I made a significant mistake with this change: the scaling factor of
batch-by-chunk is O(nSendBytes), while the scaling factor of sending
directly to players is O(nSendBytes * nActivePlayers). It seems like the
real problem is that this system isn't getting enough usage.

While it does reduce compression efficiency in some cases, it falls back
to letting the sessions do individual compression when the amount of
data is less than 256 bytes anyway (compression-threshold in
pocketmine.yml).

My motivation for scrapping this system was to reduce the broadcast
system's complexity to make it easier to thread the living shit out of
compression, but it seems like this change was a step in the wrong
direction for performance.

A few steps can be taken to improve the usefulness of this system (and
also improve output bandwidth):
- Make general entity updates use this system. Movement and velocity
  already kinda used this system, but crucially, players did not,
  because we couldn't prevent the player from receiving its own movement
  updates if we did that, which caused all kinds of problems.
  - Therefore, we need to reintroduce static "self" entity IDs, like we
    had in the shoghi days when entity ID 0 referred to the "self"
    player.
  - However, since entity ID 0 has a variety of interesting bugs since
    it usually refers to "no entity" in MCPE, it would be better to use
    1 (or 2, like MiNET does).
  - The fixed ID used should be close to zero to maximize varint
    encoding efficiency.
  - We assumed that changes to player's position and velocity would be
    ignored by the client. This assumption depends on the client and
    could be broken at any time, so it's best not to rely on it.
- Make block updates use this system (when chunk updates are not sent).
  Currently, block updates use a separate mechanism which creates a
  second batch for every active chunk, which wastes CPU, and decreases
  bandwidth efficiency on multiple fronts (reduced compression
  efficiency, more cross-thread interactions, more bytes wasted on
  RakNet packet headers).
2020-10-11 14:55:54 +01:00
Dylan K. Taylor
b172c93e45 World: do not group broadcasted packets by chunk, broadcast directly instead
Grouping packets to batch by chunk instead of by player reduces bandwidth efficiency, because the number of active chunks is almost always larger than the number of active players.
With the old mechanism, a batch of packets for each active chunk (which could be dozens, or hundreds... or thousands) would be created once, and then sent to many players. This makes the compression load factor O(nActiveChunks). Broadcasting directly is simpler and changes the load factor to O(nActivePlayers), which usually means a smaller number of larger batches are created, achieving better compression ratios for approximately the same cost (the same amount of data is being compressed, just in a different way).
2020-10-06 17:27:17 +01:00
Dylan K. Taylor
d3a3a41d2b Revert back to separated floor/wall sign
the conditionally useless properties are problematic.
2020-10-04 17:52:23 +01:00