Welcome, guest! Please login or register.

    * Shoutbox

    • King Bosnia: Any recommendations to private servers?
      October 18, 2018, 04:47:35 PM
    • FightMexoxo: oi i have the files if anyone whats em
      October 18, 2018, 12:44:42 AM
    • The Wanderer: Whoops
      October 15, 2018, 12:56:18 AM
    • The Wanderer: Making own operating system
      October 15, 2018, 12:56:11 AM
    • Travas: no
      October 07, 2018, 04:03:36 PM
    • Saltyspade10: Server still up and running?
      October 05, 2018, 07:13:41 PM
    • Wesam: Can someone upload moparscape.jar?
      October 05, 2018, 11:43:43 AM
    • Ligoe: yo
      September 30, 2018, 12:48:15 PM
    • Ligoe: how come i can't login the game
      September 30, 2018, 12:48:03 PM
    • fuzzout: Anybody here with experience in using Luna source? I'm looking to develop something, but can't seem to get any of my clients to work with it...
      September 26, 2018, 10:47:27 AM
    • `Discardedx2`: ?
      September 21, 2018, 12:24:09 PM
      September 20, 2018, 11:55:24 PM
      September 20, 2018, 11:55:07 PM
    • Vasi28: Гранд
      September 03, 2018, 07:06:22 PM
    • Rash: test
      August 30, 2018, 09:09:18 PM
    • Guruu:[link]
      August 30, 2018, 12:04:45 AM
    • Guruu: am i allowed to post links shoutbox?
      August 30, 2018, 12:03:46 AM
    • drubrkletern:[link] feedback wanted
      August 28, 2018, 03:55:17 PM
    • bugz000: Anyone got a link for the old ass silab client and cache.zip? from mopar 3.2 era :) 317
      August 25, 2018, 12:48:15 AM
    • cholland2015: Does anyone know where I can download the old moparscape client/server?
      August 24, 2018, 02:30:51 PM

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

    0 Members and 1 Guest are viewing this topic.


    • 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 {
    3.         ...
    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 {
    3.         ...
    5. }

    Code: Java
    1. publicclass NPC extends UpdatableEntity {
    3.         ...
    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.         }
    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
    14.                 //retrieve all the entities in the 32x32 area around the player
    15.                 UpdatableEntity[] results = qtree.retrieve(area);
    17.                 //construct the npc updating and player updating packets
    18.                 Packet npcUpdating =new Packet();
    19.                 Packet playerUpdating =new Packet();
    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
    Runescape Gambling

    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:
    Runescape Gambling


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


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

    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