932 Commits

Author SHA1 Message Date
Dylan K. Taylor
e58db75396 Level: Remove redundant null checks from useBreakOn()
These checks are not needed as of 3eae7a187524233f35deae028b01cf58ccd48157.
2017-12-11 16:31:43 +00:00
Dylan K. Taylor
51cec525ee Added methods for calculating sun angle and sky light level reduction by day time
Use real sky light level in Level->getFullLightAt()

close #1471
2017-12-06 12:40:52 +00:00
Dylan K. Taylor
a5f4dda918 Added documentation for Level->addChunkPacket()
this method is confusingly named
2017-12-06 11:15:17 +00:00
Dylan K. Taylor
d03fdd5f72
Liquids refactor, bug fixes and performance improvements (#1753)
* Added Liquid->getLiquidLevelDecreasePerBlock()

* Fixed lava turning into cobblestone when flowing over water

* Cache liquid flow vectors for faster entity movement

* Removed a condition that made lava impossible to get rid of
In the PC code, the equivalent code makes the delay between scheduled ticks 4 times longer. Here, it just breaks the code. I don't know what the 4x stuff is about, but this code does not produce the expected behaviour and lava works fine regardless.

* Fixed strange behaviour with liquids trying to flow into other liquids
Liquids should consider other liquids as a path of least resistance. However, they should not actually flow into them. This fixes a variety of CPU leak issues with falling water in large water bodies such as oceans.
This also fixes the plus-shape effect that liquid is supposed to produce when a source is placed above ground.

* Removed a bad optimization making liquids flowing down slopes behave undesirably

* Optimize performance of slope searching by limiting recursion depth based on previous path lengths
If we already found a step down on a previous run after 2 blocks, it doesn't make sense to continue allowing checking 4 blocks because the results will just be ignored. This allows limiting the number of recursion steps, which significantly improves the performance when flowing down slopes.
However, this will still be just as bad for performance on flat terrain as it was to start with.

* Make some Liquid methods only accept Blocks as parameters
these are only ever passed blocks anyway, doesn't make sense to allow vectors.

* Moved some things to local variables
these are each only used in one function, so it doesn't make sense for them to be class members.

* Fixed water flow down slopes going everywhere, but degraded performance again

* Lava should only search 2 blocks for a slope

* Stop wasting CPU calculating optimal flow directions for liquids with too-high decay
It calculates the flow directions and THEN doesn't use them when it
realizes the flow decay is too high. This is completely pointless.

* Use a less hacky method to handle lava flowing into water

* Doubled flow performance on flat terrain
Since calculateFlowCost() usually ends up visiting the same blocks about 6 times when on flat terrain, it makes sense to cache some stuff for when blocks get revisited so expensive dumb checks don't need to keep on being done. On my machine this produces a 50-60% performance improvement when flowing on flat terrain.

* Fixed missing return values in Liquid->onUpdate()
these return values aren't used anywhere, but we should be consistent

* Don't allow flowing back in the same direction we just came from
This reduces the recursions by about 30%, providing about the same percentage performance improvement.

* Remove Liquid's temporalVector (it's not used anymore)
primitive types for the win!

* Move liquid collide to its own method

* add sound for lava/water mix
2017-12-04 10:09:35 +00:00
Dylan K. Taylor
af68125872 Make Level->getName() less volatile
this resolves problems with crashes when getName() is called on an unloaded level. This obviously doesn't solve the root cause of the issue (level being accessed after unload) but since many things use the level name without checking if it's unloaded first, it's a bad idea for it to be volatile.

This resolves the server crash issue noted in #1527, where an exception is raised due to level unload during a tick, which subsequently causes a crash when trying to log the exception.
2017-12-04 09:57:53 +00:00
Dylan K. Taylor
88318d740a Use standard subchunk iterator code in Explosion
this causes a slight performance loss (<10%), but in a sane language this would be inlined anyway
2017-11-28 11:20:22 +00:00
Dylan K. Taylor
d3e5733ea0 Significantly improved light population performance using subchunk
direct accessing

These changes produce upwards of 2x better performance (YMMV, also
depends on the circumstances).
2017-11-28 11:20:22 +00:00
Dylan K. Taylor
4703715063 Added a SubChunkIteratorManager class for faster subchunk handling 2017-11-28 11:20:14 +00:00
Dylan K. Taylor
523a7f0999 Fix a very rare light propagation bug
This could occur when light sources were placed near each other and one of them is removed, the other's light would not be propagated far enough because the node wasn't queued for updating although it was marked as if it was.
2017-11-27 19:43:56 +00:00
Dylan K. Taylor
256527c953 Chunk: Fixed possible bug with Chunk->setBlockData()
to be honest this would probably never affect anything, but let's be consistent.
2017-11-27 19:26:20 +00:00
Dylan K. Taylor
b93691a177 Chunk: Remove redundant assignment 2017-11-27 18:58:08 +00:00
Dylan K. Taylor
48c5db4296 Chunk: Add some PhpDoc 2017-11-27 17:51:42 +00:00
Dylan K. Taylor
c564655f9b Chunk: Remove unnecessary default values
these are assigned in the constructor anyway.
2017-11-27 17:49:08 +00:00
Dylan K. Taylor
49301b0d74 Chunk: Use an SplFixedArray for subchunks 2017-11-27 17:46:48 +00:00
Dylan K. Taylor
8bc733514b LevelDB: Fixed nonsensical array access in iterator loop 2017-11-27 17:21:26 +00:00
Dylan K. Taylor
c1a6711514 Fix for explosions modifying the wrong subchunks under some circumstances 2017-11-27 17:11:52 +00:00
Dylan K. Taylor
ed195e1167 phpdoc 2017-11-23 17:27:41 +00:00
Dylan K. Taylor
667a54fd00 Store world height in the Level for faster access
this might look like a micro optimization, but it shows up big-time on profiler snapshots.
2017-11-23 17:24:37 +00:00
Dylan K. Taylor
74b074753f Bulk addition of constant visibilities
thanks PhpStorm inspections plugin for annoying the shit out of me until
I did this.
2017-11-21 14:44:10 +00:00
Dylan K. Taylor
00a9ae6c95 make use of getSavableEntities() in Level->unloadChunk()
why couldn't I have thought of this before I changed this the first time >.>
2017-11-19 18:08:42 +00:00
Dylan K. Taylor
a9df383346 generalized conditions for saving entities with chunks 2017-11-19 18:06:38 +00:00
Dylan K. Taylor
19dc22d6b3 Chunk save: skip entities which won't be saved anyway
don't just hardcode this to players
2017-11-19 17:57:54 +00:00
Dylan K. Taylor
2fd61163bf cleanup some chunks leftovers from 1.0 2017-11-19 17:52:36 +00:00
Dylan K. Taylor
5640bcb0b8 add some new leveldb keys 2017-11-19 17:43:54 +00:00
Dylan K. Taylor
ea3c7383fb Added support for handling MCPE 1.2 leveldb worlds
requires php-leveldb version >=0.2.1 and the latest version of
pmmp/leveldb-mcpe
2017-11-19 17:31:09 +00:00
Dylan K. Taylor
7e496afdd1 Fixed issues with LevelDB worlds silently getting overwritten with the default format when LevelDB extension is not loaded
Always register the level provider (to allow detecting the world format) but throw exceptions if anything tries to use it without the extension being loaded.
2017-11-19 17:28:16 +00:00
Dylan K. Taylor
12bbc764ec Fixed Level->getSafeSpawn() looking for blocks in chunk 0,0 2017-11-17 20:45:29 +00:00
Dylan K. Taylor
5178373d8a fixed overoptimized code in getSafeSpawn(), close #1248 2017-11-17 13:58:03 +00:00
Dylan K. Taylor
28188e5ef4 remove redundant count() for updateTiles 2017-11-17 13:47:54 +00:00
Dylan K. Taylor
665130561e Further cleanup on NBT dynamic field access
not sure how I missed so many of these... there are probably lots more besides :(
2017-11-17 11:19:36 +00:00
Dylan K. Taylor
6adc813a7f Fixed disable-block-ticking pocketmine.yml config not working 2017-11-16 14:45:00 +00:00
Dylan K. Taylor
aa399a1109
migrate to new CompoundTag API (#1515) 2017-11-10 15:38:21 +00:00
Dylan K. Taylor
42ed03fd02 Merge branch 'left-click-spawn-prot' 2017-11-03 11:59:26 +00:00
Dylan K. Taylor
91c256f1a9 Added Level->getTileAt() 2017-10-30 13:36:42 +00:00
Dylan K. Taylor
67af4d3b65 Cleaned up PMAnvil implementation 2017-10-29 19:13:58 +00:00
Dylan K. Taylor
d1db27016e s/facePos/clickVector/
clickVector better describes this
2017-10-27 19:05:26 +01:00
Dylan K. Taylor
c55bc2d7e9 added use-item click vector to PlayerInteractEvent
now go and make some touchscreens with maps!
2017-10-27 19:00:17 +01:00
Dylan K. Taylor
48fefae920 Added cache for tile spawn compounds
avoids expensive repetetive NBT writes on chunk sends when the tile hasn't been changed
2017-10-27 10:23:48 +01:00
Dylan K. Taylor
3b85e558ce Fixed bad documentation on Level->checkSpawnProtection() 2017-10-24 18:56:38 +01:00
Dylan K. Taylor
6daa0135d5 Cancel PlayerInteractEvent automatically on left-click block when spawn protection is triggered 2017-10-24 13:11:19 +01:00
Dylan K. Taylor
716c1f29b4 Fixed slabs again 2017-10-24 10:23:07 +01:00
Dylan K. Taylor
7b04049bb7 Throw exceptions when trying to add closed entities or tiles to levels 2017-10-20 18:22:28 +01:00
Dylan K. Taylor
30211bee82 Fixed excessive idle CPU usage for chunk ticking
"excessive" = 5%, after changes = 1.6% - YMMV, but that's my machine.
2017-10-20 15:54:22 +01:00
Dylan K. Taylor
18e4e5364f Fixed getBlock() performance degradation caused by 781de3efabcd526281fd1adc8ce881d408471563, added Level->getBlockAt() to avoid creating vectors everywhere 2017-10-20 13:22:49 +01:00
Dylan K. Taylor
50be26958a Added a helper function Entity->createBaseNBT() to cut down on boilerplate code 2017-10-19 17:36:51 +01:00
Dylan K. Taylor
5a353012de Clean up some unused imports 2017-10-19 16:39:34 +01:00
Dylan K. Taylor
584810780a Moved projectile-related classes to their own namespace 2017-10-19 12:27:44 +01:00
Dylan K. Taylor
251d5d7946 Fixed some hardcoded values in Tree 2017-10-16 12:30:46 +01:00
Dylan K. Taylor
fd847f02ad Added BaseInventory->dropContents() 2017-10-16 12:18:06 +01:00
Dylan K. Taylor
41f292d995 BlockUpdateEvent doesn't allow changing the target block anyway 2017-10-14 10:10:19 +01:00