Thread: Player Updating

Results 1 to 3 of 3
  1. #1 Player Updating 
    Registered Member
    Join Date
    Sep 2011
    Posts
    59
    Thanks given
    0
    Thanks received
    10
    Rep Power
    11
    Is there any way to update all the players without using a for loop? I was reading this - see below as well and I was curious about the Events and EventListeners to handle the movement or anything really. So I ask again, is there any way to update all the local players without using a for loop and maybe use an Event system to do the trick? I feel as if using a for loop is pretty disgusting to be quite honest.

    using events also helps prevent polling and redundancy.
    instead of continuously checking to see if a player is in an area (warning: bad code ahead)...

    Code:
    void tick() {
        for (Player player : players) {
            if (player.moved && player.x >= AREA_X1 && player.y >= AREA_Y1 && player.x <= AREA_X2 && player.y <= AREA_Y2) {
                ... area-specific logic here ...
            }
        }
    }
    we can implement something called inversion of control and decouple this into events and event listeners:
    Code:
    EventSubscriber<MovementEvent> movement_listener = EventSubscriber<MovementEvent>() {
    
                public boolean satisfied(MovementEvent event) {
                    Player player = event.player;
                    return player.x >= AREA_X1 && player.y >= AREA_Y1 && player.x <= AREA_X2 && player.y <= AREA_Y2;
                }
    
                public void handle(MovementEvent event) {
                    ... area-specific logic here ...
                }
            });
    this helps separate our concerns and make developing much easier.
    Reply With Quote  
     

  2. #2  
    Banned Player Updating Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    yeah, all player updating is, is essentially a packet that a single player sends out to be written to the socket channel. so if you were to attach an event for updating or whatever to every single player and have some sort of system that fires those events in 600ms intervals you would be okay.

    this could replace all processing for players completely, something like

    Code:
        Events.getSingleton().submit(new Event() {
              @Override
              public boolean fireWhen() {
    
                   // updating is needed every single tick, so always return true
                   return true;
              }
    
              @Override
              public void fire() {
                   // updating logic here
              }
    
         // we need this event as long as the player is online
         }.setRemoveOnFire(false));
    really bad example, but you get the idea

    although in those events, you would still have to loop through the local list to update it. there's no getting around looping lol, if you're trying to avoid them while programming... anything in java really you're not going to have a fun time

    there would also have to be a strict order of the events, because in a traditional server everything is processed serially (besides updating which is done in parallel on servers that don't suck). you wouldn't want to have a player getting reset before they get updated, or getting pre-update logic fired after they're updated, etc.

    all in all the idea sounds nice, but just too complicated to carry out and not worth it at all because you wouldn't see any performance benefits. you'd actually probably see better performance on the traditional servers that just do a normal loop through all of the entities


    if you're looking for a way to reduce overhead (lag) then look at player updating. not at updating the local list but look at the update blocks, that is what eats up the entire cycle time especially appearance updating! be sure to cache data whenever you can (most importantly the update blocks themselves, i wrote i little tutorial on it here) and micro-optimizations do matter!!
    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Banned Player Updating Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    bump, more people should give input this was a pretty good question
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. The player updating procedure
    By veer in forum Informative Threads
    Replies: 30
    Last Post: 01-08-2012, 11:24 PM
  2. Replies: 2
    Last Post: 04-22-2009, 01:19 PM
  3. [508] Player Update Masks.
    By Ian... in forum Configuration
    Replies: 9
    Last Post: 08-30-2008, 06:12 PM
  4. All 481 Player Update Masks
    By ZachHaley in forum RS2 Server
    Replies: 13
    Last Post: 07-07-2008, 07:30 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •