Commit Graph

99 Commits

Author SHA1 Message Date
2a3e6dcf00 Rename BlockIds -> BlockLegacyIds 2019-03-23 19:46:31 +00:00
3dbed830ef Fixed entities not loading on imported MCPE worlds 2019-03-21 20:03:10 +00:00
588ebe446f Fixed Chunk->setFullBlock() not creating new subchunks, closes #2821 2019-03-21 18:47:24 +00:00
5830ca958b Further out-phasing of legacy ID/meta
this paves the way for making internal IDs fully dynamic.
2019-03-17 16:01:04 +00:00
a91f49220c Chunk: Do not mark as changed on lighting updates
Since we don't save light to disk anymore, we don't need to care if a light update took place. This improves I/O performance.
2019-03-14 16:34:14 +00:00
18e16f8615 Fixed blockID truncation 2019-03-10 19:53:24 +00:00
a858103e6b Support paletted subchunks, drop all formats except leveldb 2019-03-10 19:53:24 +00:00
f83e5c195c fixed tiles and entities not getting saved on fast-deserialized chunks 2019-03-03 18:26:05 +00:00
54ef965b2a Added warnings when unknown entities and tiles are removed 2019-03-03 18:02:34 +00:00
6e00ab2069 Chunk: add getNBTentities() and getNBTtiles()
this shit is horrible, but it's needed for now...
2019-03-03 14:00:46 +00:00
6c8fa8ae28 More nullable and void typehints 2019-03-02 10:29:11 +00:00
73a565355b Make some forced-optional nullable parameters non-optional, PHP 7.1 style
these parameters did not make any sense to be optional, but were forced to be this way because of the way nullable types worked before 7.1.
2019-02-22 12:54:00 +00:00
78cb6445a5 Introduce TileFactory 2019-01-07 00:20:24 +00:00
7d827a1c65 Introduce EntityFactory
This contains all of the static stuff that was previously embedded in the Entity static root. This solves a bunch of problems like circular dependencies between parent and child classes, encapsulating logic and reducing the size of the enormous Entity.php.
2019-01-06 23:54:29 +00:00
b1cef8509a Revamp Entity construction
This is a similar refactor to the one I recently did for tiles.

- Entity::createEntity() is removed. In its place are Entity::create() (runtime creation, use where you'd use a constructor, accepts a ::class parameter, throws exceptions on unknown entities) and Entity::createFromData() (internal, used to restore entities from chunks, swallows unknown entities and returns null).
- Entity::registerEntity() is renamed to Entity::register().
- Added Entity::override() to allow overriding factory classes without touching save IDs. This allows more cleanly extending & overriding entities. This method only allows overriding registered Entity classes with children of that class, which makes code using the factory much more sane and allows to provide safety guarantees which make the code less nasty.
- Entity::getKnownEntityTypes() is renamed to Entity::getKnownTypes().
- ProjectileItem::getProjectileEntityType() now returns a ::class constant instead of a stringy ID.
- Cleaned up a bunch of nasty code, particularly in Bow.
2019-01-06 23:33:36 +00:00
adc1069ed2 Merge branch '3.5' 2019-01-04 23:28:44 +00:00
4b9a142a5d Import global functions and constants for enhanced performance
This is better for performance because these then don't need to be reevaluated every time they are called.

When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace.
This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified.

However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement.
But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations.
We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
2019-01-04 20:43:15 +00:00
a9dc447f8f Tile: make createFromData() retrieve the ID by itself 2018-12-11 14:56:25 +00:00
d72e4cb9a1 Tile: remove createNBT(), add create(), createFromData(), createFromItem() 2018-12-10 19:40:37 +00:00
4c848bb4c1 docs fixes 2018-11-22 17:07:36 +00:00
98efd27543 Remove ability to set blockID and blockdata independently
This was the cause of many inconsistency and broken world bugs. In the future (once we switch to paletted chunks) this won't be possible anyway. For now, some temporary API is provided to allow modifying chunkdata directly, but it is required that **both** must be provided.
2018-11-22 16:53:22 +00:00
e67b1a20de Merge remote-tracking branch 'origin/release/3.4' 2018-11-17 14:47:35 +00:00
f8bfbc107d Reduce chunk memory usage by 20-60% by exploiting PHP copy-on-write behaviour (#2527)
This takes advantage of two key behaviours of PHP:
1. Assigning a string does not copy the string
2. Changing an offset in a string causes the string to be copied.

These two factors combined, along with the fact that blocklight and skylight arrays are usually all-zeros, allow us to produce a significant memory usage reduction of loaded chunks.
A freshly generated PM world with 3,332 chunks loaded drops from 310MB to 200MB memory usage with these changes applied.
2018-11-17 14:46:05 +00:00
8b9ec5dde3 Merge branch 'release/3.4' 2018-11-07 22:11:27 +00:00
342a74ffcb Level: Collect garbage from chunk internals in doChunkGarbageCollection() 2018-11-07 20:01:07 +00:00
0e87cf801e Merge branch 'release/3.4' 2018-11-03 19:44:00 +00:00
a50a863ab7 Chunk: be more intelligent about fast-serializing chunks
This reduces the amount of useless data that pthreads has to copy around.
2018-11-03 19:43:35 +00:00
90482e79bc Merge branch 'release/3.4' 2018-10-21 18:23:54 +01:00
45c9caa38c Fixup some formatting issues 2018-10-21 18:15:25 +01:00
a430f7f4f7 Allow static properties and state masks to vary based on variant 2018-10-06 17:33:28 +01:00
8a062f440d Chunk: remove column methods
these were (mostly) unused, and the places they were used breaks the interface definitions. It also exposes internals that are sensitive to change.
2018-10-03 18:35:39 +01:00
848bce193c Chunk: change tile storage hash function to unbind Y coordinate
this isn't strictly needed but it is more scalable in the case of future build height limit lifts.
2018-08-19 16:56:50 +01:00
7c41bfcdf3 Removed Tile numeric runtime IDs, use block hashes instead
Tiles are level-local and are not indexed globally like entities. There is pretty much zero point to them having numeric runtime IDs.
2018-08-19 16:37:04 +01:00
28a72a93b4 Chunk: Use an SplFixedArray for heightmap
this goes on 3.1 because it changes the behaviour of chunk cloning, which might possibly break some plugins, and this isn't a bug fix.

This should see no change in behaviour other than a minor performance improvement and slight reduction in memory usage.
2018-07-05 11:58:20 +01:00
c4c6c58615 Added some missing typehints 2018-06-10 17:18:55 +01:00
857f6dd5df Chunk: Share EmptySubChunk instance with other chunks on the same thread 2018-06-04 11:44:18 +01:00
66963fbf9a Nuke block extradata
this has been superseded by multi-layer blockstorages in 1.2.14+
2018-05-19 11:03:28 +01:00
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
3962d32ffe Chunk: Remove obsolete checks for entity/tile coordinate mismatches
This code is no longer necessary, because entities are constructed with a Level instead of a Chunk since API 3.0.0-ALPHA4. This means that they will not get allocated in the wrong chunk at runtime after having been saved on the wrong chunk by something else (such as an older version of PM). They will instead be allocated in a chunk selected by bitshifting their coordinates.

This is necessary to be able to fix #1789 without causing entities affected by the infamous bitshift-on-floats bugs to inexplicably vanish.
2018-02-14 18:58:52 +00:00
a0683dbb0f Chunk: Remove useless code in fastDeserialize() 2018-01-08 21:38:30 +00:00
c16c9efdf3 Chunk: Rename unload() to onUnload()
this more accurately describes what the function does.
2018-01-02 10:50:22 +00:00
c3cc6f9880 Chunk: Clean up unnecessary checks in unload() 2018-01-02 10:48:01 +00:00
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
b93691a177 Chunk: Remove redundant assignment 2017-11-27 18:58:08 +00:00
48c5db4296 Chunk: Add some PhpDoc 2017-11-27 17:51:42 +00:00
c564655f9b Chunk: Remove unnecessary default values
these are assigned in the constructor anyway.
2017-11-27 17:49:08 +00:00
49301b0d74 Chunk: Use an SplFixedArray for subchunks 2017-11-27 17:46:48 +00:00
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
a9df383346 generalized conditions for saving entities with chunks 2017-11-19 18:06:38 +00:00
2fd61163bf cleanup some chunks leftovers from 1.0 2017-11-19 17:52:36 +00:00