1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

MapImageEngine for devbuild

Discussion in 'Development' started by MalakasPlayzMCPE, Sep 28, 2018.

  1. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    So I use a devbuild of pmmp, that has the BatchPacket removed/killed. I have the following code which I do not know how to update:
    PHP:
        public function regeneratePacketsCache(MapImage $image nullint $chunk_x nullint $chunk_y null) {
            if (
    $image === null) {
                
    $this->cache = [];
                foreach (
    $this->images as $image) {
                    
    $this->regeneratePacketsCache($image);
                }
            } else {
                if (!isset(
    $this->images[spl_object_hash($image)])) {
                    return;
                }
               
                if (
    $chunk_x === null && $chunk_y === null) {
                    foreach (
    $image->getChunks() as $chunks) {
                        foreach (
    $chunks as $chunk) {
                            
    $pk = new BatchPacket();
                            
    $pk->setCompressionLevel(7);
                            if (
    MapImageEngine::isCustomPacketSupported()) {
                                
    $pk->addPacket($chunk->generateCustomMapImagePacket());
                            } else {
                                
    $pk->addPacket($chunk->generateMapImagePacket());
                            }
                            
    $pk->encode();
                            
    $this->packet_cache[$chunk->getMapId()] = $pk;
                        }
                    }
                } else {
                    
    $chunk $image->getChunk($chunk_x$chunk_y);
                    if (
    $chunk !== null) {
                        
    $pk = new BatchPacket();
                        
    $pk->setCompressionLevel(7);
                        if (
    MapImageEngine::isCustomPacketSupported()) {
                            
    $pk->addPacket($chunk->generateCustomMapImagePacket());
                        } else {
                            
    $pk->addPacket($chunk->generateMapImagePacket());
                        }
                        
    $pk->encode();
                        
    $this->packet_cache[$chunk->getMapId()] = $pk;
                    }
                }
            }
        }
    Here is what I tried:
    PHP:
        public function regeneratePacketsCache(MapImage $image nullint $chunk_x nullint $chunk_y null) {
            if (
    $image === null) {
                
    $this->cache = [];
                foreach (
    $this->images as $image) {
                    
    $this->regeneratePacketsCache($image);
                }
            } else {
                if (!isset(
    $this->images[spl_object_hash($image)])) {
                    return;
                }
               
                if (
    $chunk_x === null && $chunk_y === null) {
                    foreach (
    $image->getChunks() as $chunks) {
                        foreach (
    $chunks as $chunk) {
                            
    $pk = new NetworkCompression();
                            if (
    MapImageEngine::isCustomPacketSupported()) {
                                
    $pk->compress($chunk->generateCustomMapImagePacket(), 7);
                            } else {
                                
    $pk->compress($chunk->generateMapImagePacket(), 7);
                            }
                            
    $this->packet_cache[$chunk->getMapId()] = $pk;
                        }
                    }
                } else {
                    
    $chunk $image->getChunk($chunk_x$chunk_y);
                    if (
    $chunk !== null) {
                        
    $pk = new NetworkCompression();
                        if (
    MapImageEngine::isCustomPacketSupported()) {
                            
    $pk->compress($chunk->generateCustomMapImagePacket(), 7);
                        } else {
                            
    $pk->compress($chunk->generateMapImagePacket(), 7);
                        }
                        
    $this->packet_cache[$chunk->getMapId()] = $pk;
                    }
                }
            }
        }
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I don't think the performance impact between sending a packet and sending a BatchPacket consisting of only one packet is that significant in your case. These make more sense if youre dealing with packets as large as crafting packets. Just cache the map packet instead of caching the map packet wrapped in a batch packet.
     
    jasonwynn10 likes this.
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    English please? I am not that good with the packets.
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Then I guess you're better off telling the author to fix it.
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    He does not seem to be that active so he will see my issue and update...
    It is a devbuild, no one uses them.
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Right, and maybe you shouldn't too ¯\_(ツ)_/¯
     
  7. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    If I don't, my server would be full of hackers and would get ddosed all the time.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.