mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 04:15:04 +00:00
Implement send buffering and queuing for network sessions (#2358)
Async compression and broadcasts are now reliable and don't have race condition bugs. This features improved performance and significantly reduced bandwidth wastage. Reduce Level broadcast latency by ticking network after levels. This ensures that session buffers get flushed as soon as possible after level tick, if level broadcasts were done.
This commit is contained in:
@@ -25,6 +25,7 @@ namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\network\mcpe\CompressBatchPromise;
|
||||
use pocketmine\network\mcpe\NetworkCompression;
|
||||
use pocketmine\network\mcpe\PacketStream;
|
||||
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
|
||||
@@ -38,7 +39,7 @@ class CraftingManager{
|
||||
/** @var FurnaceRecipe[] */
|
||||
protected $furnaceRecipes = [];
|
||||
|
||||
/** @var string */
|
||||
/** @var CompressBatchPromise */
|
||||
private $craftingDataCache;
|
||||
|
||||
public function __construct(){
|
||||
@@ -105,16 +106,18 @@ class CraftingManager{
|
||||
$batch = new PacketStream();
|
||||
$batch->putPacket($pk);
|
||||
|
||||
$this->craftingDataCache = NetworkCompression::compress($batch->buffer);
|
||||
$this->craftingDataCache = new CompressBatchPromise();
|
||||
$this->craftingDataCache->resolve(NetworkCompression::compress($batch->buffer));
|
||||
|
||||
Timings::$craftingDataCacheRebuildTimer->stopTiming();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pre-compressed CraftingDataPacket for sending to players. Rebuilds the cache if it is not found.
|
||||
*
|
||||
* @return string
|
||||
* @return CompressBatchPromise
|
||||
*/
|
||||
public function getCraftingDataPacket() : string{
|
||||
public function getCraftingDataPacket() : CompressBatchPromise{
|
||||
if($this->craftingDataCache === null){
|
||||
$this->buildCraftingDataCache();
|
||||
}
|
||||
|
Reference in New Issue
Block a user