1. Guest, as per the stickied thread, this forum has not been in use since 2014. All bugs and feature requests should be posted to JIRA.

Feature View Distance Adjusts to Amount of Players Online

Discussion in 'Bugs & Feature Requests' started by CCT, Jul 11, 2013.

  1. CCT

    CCT
    Supporter

    Not sure if this would even be possible, but I thought of it today while I was getting frustrated with a small view distance. I think this feature would be very nice and cool. I'm sure many servers would love it.
     
    • Like Like x 2
  2. Sounds an amazing idea, I'm sure it could be possible
     
  3. I second this idea too.
     
  4. That would be pretty damn awesome:D
     
  5. That would be pretty epic. Im going to spend the rest of my day to see if i can make a plugin like that. If i can ill post it or email whoever wants it.
     
    • Optimistic Optimistic x 1
  6. joehot200

    Supporter

    I suggested this a while ago, however i suggested it with entities and not view distance.

    md_5, sounds like a good idea.
     
  7. joehot200

    Supporter

    Well, here is some TPS Calculating code:

    (Declare a double called tps at the top)
    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    {
    long sec;
    long currentSec;
    int ticks;
    int delay;

    @Override
    public void run()
    {
    sec = (System.currentTimeMillis() / 1000);

    if(currentSec == sec)
    {
    ticks++;
    }
    else
    {
    currentSec = sec;
    tps = (tps == 0 ? ticks : ((tps + ticks) / 2));
    ticks = 0;
    }
    }
    }, 0, 1);

    Obviously slightly offtopic, however my blocking mob-spawn code is this: (Yeah, its inefficient, again, i coded this a while ago)
    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    {
    @Override
    public void run(){

    if (Main.tps <= 18){
    if (MyPlayerListener.reducemobs == false){
    MyPlayerListener.reducemobs = true;
    //Bukkit.getServer().broadcastMessage(ChatColor.BOLD + "[Debug] Server is starting to lag, mobs reduced.");
    }
    if (Main.tps <= 16){
    if (MyPlayerListener.stopmobs == false){
    MyPlayerListener.stopmobs = true;
    //Bukkit.getServer().broadcastMessage(ChatColor.RED + "[Debug] Mobs temporarily disabled");
    }
    }
    }else{
    if (MyPlayerListener.stopmobs == true){
    MyPlayerListener.stopmobs = false;
    //Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "[Debug] Mob spawning enabled!");
    }
    if (MyPlayerListener.reducemobs == true){
    MyPlayerListener.reducemobs = false;
    //Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "[Debug] Mobs are now spawning at the normal rate!");
    }
    }



    }
    @EventHandler(priority = EventPriority.MONITOR)
    public void onCreatureSpawnEvent(CreatureSpawnEvent event){
    if (event.isCancelled()) event.setCancelled(false);
    if (reducemobs == true){
    if (cancelmobs == true){
    cancelmobs = false;
    event.setCancelled(true);
    }else if (stopmobs == true){
    event.setCancelled(true);
    }else{
    cancelmobs = true;
    }
    }
    }
     
  8. CCT

    CCT
    Supporter

    I think this would be especially useful on Factions servers that need a small view distance to handle the amount of players online. Bestle :p
     
  9. Sway

    Artist Supporter

    As cool as this sounds; I think it might be a bit more doable if the server were to cut down on certain things when the tps drops below x.xx defined value.
     
  10. thnx joehot200 im still working on it. CollinPotato, do you want farther render for less or more ppl? Cause i think ive got it
     
  11. And spigot.yml would probably handle it like view-distance: dynamic
     
  12. I was actually developing something along the lines of this a while back, but I never completed it.
     
  13. CCT

    CCT
    Supporter

    Would this be possible md_5
     
  14. Sorry for gravedigging this thread, but I just did a proof of concept of permission based view-distance, so this too is definetly possible. I, however, am not sure whether this affects the performance or not. Checking the permission for player on each chunk load and send could be heavy.

    What do other people think, would this be feasible?
     
  15. Here's an image showcasing the functionality. These 2 players are looking at the same spot in the map, but the other one sees further.
    [​IMG]

    I first integrated this into Spigot, but afterwards decided to use some reflection to build a plugin. The plugin however is quite fragile and isn't that clean of an implementation of this feature. I'd really like to program a patch for mainline Spigot to have an API to set view distance per player. What does @md_5 think?
     
    • Like Like x 1
  16. Dmck2b

    Services Staff

    You could always just create it and submit it as a PR.
     
    • Friendly Friendly x 1
  17. Before I start doing the extra work needed, I'd like to know whether this kind of change would be feasible or not.
     
  18. md_5

    Administrator Developer

    Chunk unloading is based on view distance.
    If you start changing the distance for different people, or shrink it, chunks could leak.
     
    • Like Like x 1
  19. Still trying to wrap my head around PlayerChunkMap, didn't know of this.

    Wouldn't there be a way to prevent this? I mean, I have everything working, if we exclude changing player's view distance on-the-fly without relogging to server and that nasty probability of chunk leaks.

    Maybe you could guide me to right direction? Not sure how busy you are though.