Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • DeathsChaos9: Well damn, long time no see m8
      May 27, 2018, 10:37:06 PM
    • usman555: i remembered out of nowhere and came to check how mopar was going
      May 27, 2018, 08:34:39 PM
    • usman555: remember azaruth, deathz
      May 27, 2018, 08:34:24 PM
    • usman555: hey
      May 27, 2018, 08:33:56 PM
    • Vain_: buying gf
      May 27, 2018, 01:53:12 PM
    • charmie: WILKO MY MAIN MAIN!
      May 26, 2018, 08:26:59 PM
    • DeathsChaos9::|
      May 26, 2018, 01:27:54 AM
    • Saltyspade10: Okay I won't be back
      May 24, 2018, 07:12:40 AM
    • [email protected]: im buying an ad banner from graham the owner need to get in contact
      May 23, 2018, 08:57:06 PM
    • [email protected]: any mods on
      May 23, 2018, 08:56:49 PM
    • kepoly: 11 years ago, damn
      May 23, 2018, 01:38:39 PM
    • B50: Sever error what happen
      May 22, 2018, 08:23:40 PM
    • The Soul: 10 years later
      May 21, 2018, 05:23:10 PM
    • The Soul: wow people are still here?
      May 21, 2018, 05:19:27 PM
    • Wilkooo: and apologies to the OG forum guys on behalf of that fudgewit dr house that pretty much killed this entire domain
      May 21, 2018, 04:14:28 PM
    • Wilkooo: shoutout to all those that played back in the beginning, all new people that hang around now seem to be pretty braindead
      May 21, 2018, 04:13:54 PM
    • Wilkooo: born sep 2016 - died whenever pink eggs resigned
      May 21, 2018, 04:11:29 PM
    • Wilkooo: Rip moparscape rsps
      May 21, 2018, 04:11:10 PM
    • puta loca: or what section can i ask this
      May 21, 2018, 05:45:08 AM
    • puta loca: does someoen has platinum ps v2 files?
      May 21, 2018, 05:44:59 AM

    Author Topic: (Concept) Abstract entity updating  (Read 883 times)

    0 Members and 1 Guest are viewing this topic.

    OfflineCres

    • Member
    • ****
    • Posts: 1,392
    • Thanks: +0/-0
      • View Profile
    (Concept) Abstract entity updating
    « on: March 28, 2016, 08:43:36 PM »
    This is a concept/design idea that I recently had and decided to sketch out to see if it could work. Not only could it work, there's also some major performance optimizations that this system brings with it.

    What is abstract entity updating?

    Well, on some servers you may have seen an efficient abstract combat system; where players and NPCs are treated alike in a single system that processes both.
    This very same concept can be applied to the updating process. Players and NPCs have very similar updating processes, allowing for abstraction. To implement this feature on an existing server would require a major overhaul of the updating process, the Player and NPC classes and a few more, which I will discuss below.

    Why implement it?

    This system means you will only have to loop through all the entities once per cycle and construct the player updating and npc updating packet for a single player in one go. This saves CPU cycles. When combined with an efficient 2D lookup method (I highly suggest a quadtree, but morton codes are a good alternative albeit more tricky to implement but are way more effective), this allows you to drastically speed up the player updating process.

    How to make it work

    First of all, you have to create either an interface or an abstract class to allow for abstraction. I am unsure if you can cast an interface to the class that implements the interface but I am sure this is the case with abstract classes, so here is one:

    (demonstrational; doesn't work and isn't finished)
    Code: Java
    1. publicabstractclass UpdatableEntity {
    2.  
    3.         ...
    4.  
    5. }

    The next thing you want to do is to make your Player and NPC classes extend this class, so they become a subclass of UpdatableEntity;

    Code: Java
    1. publicclass Player extends UpdatableEntity {
    2.  
    3.         ...
    4.  
    5. }

    Code: Java
    1. publicclass NPC extends UpdatableEntity {
    2.  
    3.         ...
    4.  
    5. }

    Now you want to create a central system that stores both Players and NPCs (which can be done now because they both inherit the UpdatableEntity class), like so:

    Code: Java
    1. ArrayList<UpdatableEntity> updatables =new ArrayList<UpdatableEntity>();
    2. ArrayList<NPC> npcs =new ArrayList<NPC>();
    3. ArrayList<Player> players =new ArrayList<Player>();
    The reason you also have the npcs and players lists is because you want to access them when you have to. There is no need to fetch npcs+players if you only want to process the npcs and there is no need to fetch npcs+players if you only want to process the players. (example below)

    The next part is optional but definately suggested. You'll want to create a 2D lookup mechanism, created with the updatable entities.
    The reason for this is performance. For all the people currently owning a server, think of it this way: You're essentially storing all your players and all your npc's in a single list. It is very unlikely for your server to benefit from any of the performance increases by this system if you're going to use the standard way of searching entities in a given range.

    I suggest using a quadtree or morton codes.

    The implementation would look like this:
    Code: Java
    1. publicvoid updatePlayers(){
    2.         //create a quadtree to hold all the updatables
    3.         QuadTree<UpdatableEntity> qtree =new QuadTree<UpdatableEntity>();
    4.         for(UpdatableEntity e : updatables){
    5.                 int x = e.getX();
    6.                 int y = e.getY();
    7.                 qtree.insert(e, x, y);
    8.         }
    9.        
    10.         //update all the players
    11.         for(Player p : players){//this is why we still store npcs and players seperately
    12.                 Area area =newArea(p.getX()-15, p.getY()-15, p.getX()+16, p.getY()+16);//32x32 area
    13.                
    14.                 //retrieve all the entities in the 32x32 area around the player
    15.                 UpdatableEntity[] results = qtree.retrieve(area);
    16.                
    17.                 //construct the npc updating and player updating packets
    18.                 Packet npcUpdating =new Packet();
    19.                 Packet playerUpdating =new Packet();
    20.                
    21.                 for(UpdatableEntity e : results){
    22.                         if(e.isNPC()){
    23.                                 appendUpdates(npcUpdating, e);
    24.                         }else{
    25.                                 appendUpdates(playerUpdating, e);
    26.                         }
    27.                 }
    28.                 p.sendPacket(npcUpdating);
    29.                 p.sendPacket(playerUpdating)
    30.         }
    31. }

    I don't know if anyone came up with this or has something like this but I haven't seen it done before.

    Also, thanks to Sini for explaining morton codes; I really learned a lot :D

    Thank you for reading this and I hope it has given you some inspiration :)
    « Last Edit: March 28, 2016, 09:48:22 PM by Cres »
    And I can find myself alone with just my thoughts
    As time crumbles away

    Avenged Sevenfold - Darkness Sourrounding
    RS2Ad banner

    OfflineFabrice L

    • Member
    • ***
    • Posts: 195
    • Thanks: +0/-0
      • View Profile
    Re: (Concept) Abstract entity updating
    « Reply #1 on: March 29, 2016, 06:41:54 AM »
    I'll take a closer look at Quad trees and Morton code, I like experimenting with stuff I don't know.

    Looks nice btw
    ClassicLive #135 RSC:
    http://classic-live.net
    RS2Ad banner

    Offlinesini

    • Member
    • ****
    • *
    • *
    • Posts: 5,785
    • Thanks: +0/-0
      • View Profile
    Re: (Concept) Abstract entity updating
    « Reply #2 on: March 29, 2016, 10:24:03 AM »
    Cool
    RS2Ad banner

    OfflineCres

    • Member
    • ****
    • Posts: 1,392
    • Thanks: +0/-0
      • View Profile
    Re: (Concept) Abstract entity updating
    « Reply #3 on: March 29, 2016, 10:49:33 AM »
    Thanks

    Working on implementing this on my server since I hadn't touched player updating yet.
    And I can find myself alone with just my thoughts
    As time crumbles away

    Avenged Sevenfold - Darkness Sourrounding

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal