Solved Make maps update instantly

Discussion in 'Plugin Development' started by Manuman1998, Nov 19, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Manuman1998

    Hello,

    Basically, I want a map to update instantly when I draw new stuff on it using a MapRenderer.
    Right now its just updating too slow, I see some parts of the old picture and some of the new one.
    Is there any way to fix that?

    Thank you for helping :)
     
  2. Offline

    GusGold

    Manuman1998
    I'm going to assume that the rendering part is wholly client side, so not without client mods.
    But, perhaps sending chunk(?) data to the player might encourage the map to be updated?
     
  3. Offline

    desht

    It's most certainly possible to do without any client mod. Just call player.sendMap(mapView) from within your render() method when you're done rendering; the image will appear immediately on the client's map.

    However, be aware that calling sendMap() will trigger another call to render(), so if you're not careful you can get into all sorts of recursive call trouble and hang the server. One good way to do it is to like this:

    PHP:
    public void render(MapView mapMapCanvas canvasPlayer player) {
      if (
    updateNeeded) {
         
    // ...do your drawing work...
         
    updateNeeded false;
         
    player.sendMap(map);  // make sure updateNeeded is false here!
      
    }
    }
    where updateNeeded is a boolean field in your renderer class. Set it to true when your data changes such that a re-render is needed. If your map has a per-player context (displays a different image depending on who's looking at it), you might want to use a Set<String> for your updateNeeded, to track which players need an update.

    Remember that render() is called every tick when a player is holding a map, so you want to exit as soon as possible if there isn't anything to draw.

    See https://github.com/desht/ScrollingM...desht/scrollingmenusign/views/SMSMapView.java for an example (the render() method is down at the end).
     
    DarkBladee12 and Manuman1998 like this.
  4. Offline

    Manuman1998

    Thank you really much :) That works perfect :D My NyanCat-Map (/GifMap) is now working ^^
     
    desht likes this.
Thread Status:
Not open for further replies.

Share This Page