1083 Commits

Author SHA1 Message Date
Dylan K. Taylor
3a31c531af Level: remove unused import 2018-06-05 13:04:24 +01:00
Dylan K. Taylor
9644766df3
Merge pull request #2213: Scheduler API refactor, plugins now have their own schedulers
- Removed `Server->getScheduler()`. All plugins now have their own scheduler which is accessible using `Plugin->getScheduler()`. Aside from being syntactically more concise and pleasant, this also allows much more effective management of tasks when plugins are disabled.
- Removed `PluginTask` class. Before this PR it was necessary for plugin tasks to descend from `PluginTask` to ensure that the server could clean them up correctly on plugin disable. This is no longer necessary, so the `PluginTask` class has been removed. Plugins may now utilize the `Task` class as a base if they like.
- Added `Server->getAsyncPool()`. Since the global scheduler does not exist any more, it does not manage the server's `AsyncPool` any more. Additionally, `ServerScheduler` was previously bloated by a lot of `AsyncTask` related methods, which are now not necessary because direct access to `AsyncPool` is granted instead.

- `ServerScheduler`:
  - `ServerScheduler` has been renamed to `TaskScheduler` since it is now a general-purpose task scheduler which is non-dependent on the user. This allows much greater flexibility and also makes it possible to unit-test.
  - All `AsyncTask`/`AsyncPool` related methods have been removed - the task scheduler does not manage the async pool anymore.
    - Calls to `Server->getScheduler()->scheduleAsyncTask()` should be replaced with `Server->getAsyncPool()->submitTask()`.
    - Calls to `Server->getScheduler()->scheduleAsyncTaskToWorker()` should be replaced with and `Server->getAsyncPool()->submitTaskToWorker()`.

## Backwards compatibility
This poses significant backwards compatibility breaks for any plugins utilizing Tasks or AsyncTasks. These breaks are described above, along with basic upgrade steps. The upgrade process is quite straightforward.

## Follow-up
A large part of the goal with this pull request is to modularize these parts of the code so that they can be reused and also unit-tested. I would like to remove the existing test set from TesterPlugin at some stage when the AsyncPool can operate without a Server.

Because of the above, I am considering making further backwards incompatible changes directly to `AsyncTask` to remove the `Server` parameters from `onCompletion()` and `onProgressUpdate()`. These shouldn't be too difficult to upgrade from and can be prepared for in advance.
2018-06-04 11:54:43 +01:00
Dylan K. Taylor
857f6dd5df Chunk: Share EmptySubChunk instance with other chunks on the same thread 2018-06-04 11:44:18 +01:00
Dylan K. Taylor
fa21cd96c5 Tiles no longer store their NBT at runtime
This is a significant breaking change for anything utilizing Tiles as they now do not store their NBT at runtime anymore.
This is another step in the process of ridding PocketMine-MP of runtime NBT.

It can be noticed that all tiles are now using class fields to store properties instead of NBT, which is much faster, uses less memory and is also more concise when written in code.

Highlights:
- Tile->namedtag has been removed.
- Tile->saveNBT() now accepts a CompoundTag() parameter. Typically it's expected that this will be fed a newly-created CompoundTag (this part may be improved in the future).
- New internal methods Tile->readSaveData() and Tile->writeSaveData() have been added. Instead of overriding __construct() and saveNBT() to load and save properties from NBT, you should now implement these methods instead.

This is not final and will see further changes before it's done.
2018-06-03 18:29:08 +01:00
Dylan K. Taylor
b6b0bbde18 Level: remove nonsensical code from generateChunkCallback()
it's impossible for this to be null when we just set it to a Chunk object. It's assigned directly to the chunk index.
2018-06-01 19:47:47 +01:00
Dylan K. Taylor
6047810113 Level: remove useless null checks for fastDeserialize() returns 2018-06-01 17:02:29 +01:00
Dylan K. Taylor
05ef13b23a Merge branch 'master' into scheduler-nuke
# Conflicts:
#	src/pocketmine/level/Level.php
2018-05-31 10:40:10 +01:00
Dylan K. Taylor
c493d0e6ac Level: Stop unnecessarily initializing the generator on the main thread
this is just slowing down startup times for no good reason.
2018-05-31 10:22:44 +01:00
Dylan K. Taylor
d03f36ebee First look at splitting up AsyncPool and ServerScheduler
This commit contains quite a few breaking changes with respect to how AsyncTasks are handled. This is necessary to allow separation of the ServerScheduler and the AsyncPool, because in the future the ServerScheduler may be removed and instead there will be isolated per-plugin sync-task schedulers - but we cannot have every plugin with its own worker pool for memory usage reasons if nothing else.

The following things have changed:
- ServerScheduler: scheduleAsyncTask(), scheduleAsyncTaskToWorker(), getAsyncTaskPoolSize(), increaseAsyncTaskPoolSize() and similar methods have all been removed. Additionally the static \$WORKERS field has been removed.
- Server: added API method getAsyncPool(). This grants you direct access to the server's AsyncPool. Calls to getScheduler()->scheduleAsyncTask() and scheduleAsyncTaskToWorker() should be replaced with getAsyncPool()->submitTask() and submitTaskToWorker() respectively.
2018-05-30 12:20:10 +01:00
Dylan K. Taylor
0a50b8cb9b Removed imports left over from 4f8f334436c69336d1bc2811717983544eda41e8 2018-05-29 11:42:12 +01:00
Dylan K. Taylor
6d53350291 Level: Moved LightPopulationTask out of generator namespace 2018-05-29 11:20:27 +01:00
Dylan K. Taylor
ad61d70eee Level: added getBiome()
this will be needed for weather impl, amongst other things.
2018-05-29 11:10:06 +01:00
Dylan K. Taylor
353a1d69db Level: move getHeightMap() to be more consistent 2018-05-29 11:10:06 +01:00
Dylan K. Taylor
4f8f334436 Replaced usages of Math::floorFloat() with (int) floor() and Math::ceilFloat() with (int) ceil()
Once upon a time, these userland functions were faster than calling builtins, but not anymore. According to my test the Math functions are twice slower in PHP 7.2 with typehints and 50% slower without typehints.

Inlining is slightly faster than using builtins, but the difference is very small - not worth making the code look any more ugly than it does already.
2018-05-28 18:54:35 +01:00
Dylan K. Taylor
71fdd59c4c Level: fine-tuned getCollisionCubes() a little bit
since we're getting the BBs anyway, what's the point in delegating this job to the block?
2018-05-28 17:41:12 +01:00
Dylan K. Taylor
0a9ed059d6 Level: fixed logic of getCollisionBlocks() to match getCollisionCubes() 2018-05-28 17:40:05 +01:00
Dylan K. Taylor
63ab27550a Level: Use bitshifts instead of division in some cases 2018-05-28 14:02:32 +01:00
Dylan K. Taylor
d612988882 Level: fixed more off-by-one errors
these are the same crap as the previous commit, but with whole chunks instead of blocks.
2018-05-28 14:00:00 +01:00
Dylan K. Taylor
c9a0c381b1 Level: fixed logical errors in getCollisionBlocks() and getCollisionCubes()
This is the same bug that Entity->getBlocksAround() had, except this actually checks for BB intersections. What this means is that as a result of the bug, one extra layer of blocks is unnecessarily checked on the max sides of the BB.

For example:
Assume you have a BB with maxY -5.5
You're definitely colliding with block -6 (because you're inside it) and you want to check an extra block in case you hit something weird like a fence.
So you want to check _at most_ up to block -5 (inclusive).

Following this maths:
-5.5 + 1 = -4.5
ceil(-4.5) = -4

This causes us to check block -4 unnecessarily. This may be a performance waste - depending on the BB size it could be proportionally a lot of blocks getting unnecessarily checked. This has not been benchmarked.
2018-05-28 12:37:17 +01:00
Dylan K. Taylor
f2511983cf Level: use increment operation for updating time 2018-05-19 16:05:08 +01:00
Dylan K. Taylor
bac649137b Level: fixed doc comment for getSafeSpawn() 2018-05-19 14:02:54 +01:00
Dylan K. Taylor
71224f51d5 Level: cleaned up some nonsensical code in getSafeSpawn()
it's impossible for this function to return false because $spawn is guaranteed to be a Vector3 when it's checked in instanceof.
2018-05-19 13:18:20 +01:00
Dylan K. Taylor
6c3fc4af46 Level: switch order of addEntity() and removeEntity()
now it's consistent with addTile() and removeTile()
2018-05-19 13:14:11 +01:00
Dylan K. Taylor
9bc860f7a8 LevelDB: fixup extra-data handling, don't delete it - just don't read it
we'll need this once multi-layer block storages are implemented.
2018-05-19 11:35:54 +01:00
Dylan K. Taylor
66963fbf9a Nuke block extradata
this has been superseded by multi-layer blockstorages in 1.2.14+
2018-05-19 11:03:28 +01:00
Dylan K. Taylor
210e108574 Level: add a null coalesce
meant to add this before push but wasn't thinking clearly...
2018-05-18 11:28:52 +01:00
Dylan K. Taylor
813437e3ee Level: Avoid unnecessary use of getChunk()
this is completely pointless.
2018-05-18 11:27:53 +01:00
Dylan K. Taylor
24295ce02f Level: Avoid creating useless throwaway objects in sensitive functions 2018-05-18 11:05:41 +01:00
Dylan K. Taylor
29fd26627e Level: Change isInWorld signature to use ints instead of floats
this is only used in one place, where it's being given floats, and it's 10% faster to use int for this because it won't convert it.

It is also 25% faster to remove typehints and 60% faster to inline it. We really need a proper PHP preprocessor for inlining.
2018-05-18 11:01:13 +01:00
Dylan K. Taylor
22b91aaa24 SubChunkIteratorManager: Added method invalidate() to allow destroying stale chunk refs conveniently
this could be necessary for reusable long-life iterators when chunks get replaced.
2018-05-18 09:52:27 +01:00
Dylan K. Taylor
c285295037 Merge branch 'release/alpha12' 2018-05-17 18:40:24 +01:00
Dylan K. Taylor
ed65e91a3c Tree: avoid astonishing behaviour with dark-oak and acacia saplings
ref #1973, these should simply not grow at all since they are not implemented yet.
2018-05-12 10:03:20 +01:00
Dylan K. Taylor
b21572774a Tool: cleanup durability handling, closes #379
long overdue... this isn't quite as extensible as the original api3/blocks system was, but this is primarily intended to replace Item->useOn(). If plugins want to use it it can be extended later on.
2018-05-10 19:48:51 +01:00
Dylan K. Taylor
b8523cb304 Merge branch 'remove-weak-position' 2018-05-10 13:53:07 +01:00
Dylan K. Taylor
197102ca3d Level: fixed blocks not dropping when not broken by player
closes #2172
2018-05-05 21:50:28 +01:00
Dylan K. Taylor
8228774ad4 Remove extra data, this time without API breaks
this is necessary because the next MCPE release will probably be made before the next PM release.
2018-05-02 12:08:44 +01:00
Dylan K. Taylor
d80c471ae1 Typehints on missed sound and particle APIs 2018-05-02 11:44:18 +01:00
Dylan K. Taylor
5368120f13 Level: remove redundant getAutoSave() condition in close()
this is already checked by save() anyway.
2018-05-01 18:47:08 +01:00
Dylan K. Taylor
2e7db552dc Level: __construct() now accepts a LevelProvider object instead of string, string
This is made possible by the removal of LevelProvider dependence on their Levels, and furthers the goal of #2024.
2018-05-01 18:43:11 +01:00
Dylan K. Taylor
dfa6cd2b7e Biome: Moved biome classes from level\generator\* to level\biome 2018-05-01 14:07:46 +01:00
Dylan K. Taylor
96d26a77a1 Explosion: set block damage to zero on destruction 2018-04-16 14:30:54 +01:00
Dylan K. Taylor
532269a484 Implemented block break XP drops 2018-04-15 19:03:18 +01:00
Dylan K. Taylor
f47f593555 Level: Removed fire hack from destroyBlockInternal()
this was causing unexpected behaviour particularly on burning trees, whereby fire would be unconditionally extinguished if the block below it was removed.
2018-04-10 09:59:40 +01:00
Dylan K. Taylor
646455f6e8 fixed painting particles, removed DestroyParticle
it didn't last long because they changed how this works... yuk
2018-04-09 16:26:15 +01:00
Dylan K. Taylor
e85fc54037 LevelSoundEventPacket: found unknown field
wtf mojang
2018-04-07 11:35:35 +01:00
Dylan K. Taylor
3134fa2744 Fixed FloatingTextParticle YET AGAIN
how many fucking ways can you break nametags Mojang???
2018-04-04 16:59:39 +01:00
Dylan K. Taylor
5b7b2dd0e2 Merge changes from ALPHA11 for 1.2.13 2018-04-04 11:31:39 +01:00
Dylan K. Taylor
5ce55bd3b0 duct tape for block ID remapping 2018-04-04 11:00:39 +01:00
Dylan K. Taylor
eba1ca030c Fix variadic type docs ...again
PhpStorm changed its mind how it wants these documenting in 2018.1, and apparently the correct syntax follows the PHP code.
2018-04-02 12:33:24 +01:00
Dylan K. Taylor
c0c684b12e Removed the need for paintings to check for destruction on schedule
Since we have a mechanism for triggering things on entities anyway, make use of it to do more than just forcing movement updates.
2018-03-25 13:15:10 +01:00