Thread: [PI] MAX_PLAYERS Array

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22
  1. #11  
    Registered Member
    Join Date
    May 2017
    Posts
    31
    Thanks given
    11
    Thanks received
    4
    Rep Power
    11
    Quote Originally Posted by Andys1814 View Post
    And how would using an ArrayList solve this?
    The size of the ArrayList is exactly the number of players online and not MAX_PLAYERS.
    Yes you can have an IF statement to skip the null entries in an array but that still an extra O( n ) steps.
    So over 30+ loops this adds up.

    Unless I'm wrong. Then please correct me.

    Quote Originally Posted by Kris View Post
    List only loops from 0 til size(amount of objects in the list, not the length of the backing array).
    A bit less looping, yes. However if you're looking to find players by name, go with my suggestion above. Use a map of <string(username), player(the player object)>; always stick to one format and you have no problems whatsoever; o(1) lookup time, no looping or anything.
    We are not looking for anything specific. We just want to improve the overall efficiency of PI code. So wherever we can we are.

    Also in PI (in my cleaned source anyway): It was initialised like this


    Code:
            public static Player players[] = new Player[Settings.MAX_PLAYERS];
    	static {
    		for (int i = 0; i < Settings.MAX_PLAYERS; i++)
    			players[i] = null;
    	}
    So looping through size would in-fact be O( n ) steps
    Reply With Quote  
     

  2. Thankful user:


  3. #12  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by _jordan View Post
    i would also probably do it this way, and store all values in memory and just have some port of get method. load times are faster.

    Code:
    public Player get(String username) {
    return map.get(username);
    }
    code for OP
    Yeah, I'd definitely use a method for getting a player through a map rather than directly accessing the map. That's because I'd make the get() method as you showed here actually force-format the username string, so it replaces _'s with spaces(or vice versa) and makes all letters lowercase - just to prevent accidental mistakes; the format needs to always remain the same. Same goes with adding to the map.
    Attached image
    Reply With Quote  
     

  4. #13  
    Registered Member
    Join Date
    May 2017
    Posts
    31
    Thanks given
    11
    Thanks received
    4
    Rep Power
    11
    Quote Originally Posted by _jordan View Post
    i would also probably do it this way, and store all values in memory and just have some port of get method. load times are faster.

    Code:
    public Player get(String username) {
    return map.get(username);
    }
    code for OP
    We have a similar way.
    But we don't need to get the user by name.
    Reply With Quote  
     

  5. #14  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by Danu View Post
    The size of the ArrayList is exactly the number of players online and not MAX_PLAYERS.
    Yes you can have an IF statement to skip the null entries in an array but that still an extra O steps.
    So over 30+ loops this adds up.

    Unless I'm wrong. Then please correct me.



    We are not looking for anything specific. We just want to improve the overall efficiency of PI code. So wherever we can we are.

    Also in PI (in my cleaned source anyway): It was initialised like this


    Code:
            public static Player players[] = new Player[Settings.MAX_PLAYERS];
    	static {
    		for (int i = 0; i < Settings.MAX_PLAYERS; i++)
    			players[i] = null;
    	}
    So looping through size would in-fact be O steps
    Why the fuck are you nulling all the fields right after constructing it? All the values in the array will by default be nulls.
    If you want to improve the overall efficiency, accept my suggestion lol that one suggestion alone would improve the efficiency of the server more than you changing it from an array to an arraylist.

    Regardless though these are all micro-optimizations here, use a profiling tool if you wish to truly optimize that shitfest of a source.
    Attached image
    Reply With Quote  
     

  6. Thankful users:


  7. #15  
    Respected Member


    George's Avatar
    Join Date
    Mar 2009
    Posts
    7,099
    Thanks given
    2,226
    Thanks received
    3,146
    Rep Power
    5000
    Debating the efficiency benifit between an array and a list, lol. Neither is going to bottleneck you.
    Attached image

    Spoiler for Spoilers!:
    Attached image
    Attached image
    Attached image
    Attached image
    Reply With Quote  
     

  8. #16  
    WVWVWVWVWVWVWVW

    _jordan's Avatar
    Join Date
    Nov 2012
    Posts
    3,046
    Thanks given
    111
    Thanks received
    1,848
    Rep Power
    5000
    Quote Originally Posted by Danu View Post
    The size of the ArrayList is exactly the number of players online and not MAX_PLAYERS.
    Yes you can have an IF statement to skip the null entries in an array but that still an extra O( n ) steps.
    So over 30+ loops this adds up.

    Unless I'm wrong. Then please correct me.



    We are not looking for anything specific. We just want to improve the overall efficiency of PI code. So wherever we can we are.

    Also in PI (in my cleaned source anyway): It was initialised like this


    Code:
            public static Player players[] = new Player[Settings.MAX_PLAYERS];
    	static {
    		for (int i = 0; i < Settings.MAX_PLAYERS; i++)
    			players[i] = null;
    	}
    So looping through size would in-fact be O( n ) steps
    i have never looked in a PI server before and now i wish i never do lol
    Attached image
    Attached image
    Reply With Quote  
     

  9. #17  
    Registered Member
    Join Date
    May 2017
    Posts
    31
    Thanks given
    11
    Thanks received
    4
    Rep Power
    11
    Quote Originally Posted by Kris View Post
    Why the fuck are you nulling all the fields right after constructing it? All the values in the array will by default be nulls.
    If you want to improve the overall efficiency, accept my suggestion lol that one suggestion alone would improve the efficiency of the server more than you changing it from an array to an arraylist.

    Regardless though these are all micro-optimizations here, use a profiling tool if you wish to truly optimize that shitfest of a source.
    I think you're mistaken. This was from the cleaned source which we got online. Having noticed exactly what your saying is what triggered us to change all the logic behind how this works.
    Reply With Quote  
     

  10. #18  
    Respected Member


    George's Avatar
    Join Date
    Mar 2009
    Posts
    7,099
    Thanks given
    2,226
    Thanks received
    3,146
    Rep Power
    5000
    Quote Originally Posted by Danu View Post
    I think you're mistaken. This was from the cleaned source which we got online. Having noticed exactly what your saying is what triggered us to change all the logic behind how this works.
    It’s going to take a bit more than changing how you store player objects, to get better performance in PI.
    Attached image

    Spoiler for Spoilers!:
    Attached image
    Attached image
    Attached image
    Attached image
    Reply With Quote  
     

  11. #19  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by Danu View Post
    I think you're mistaken. This was from the cleaned source which we got online. Having noticed exactly what your saying is what triggered us to change all the logic behind how this works.
    I'm mistaken about what? The fact that it's a shitfest of a source?
    Just say the sentence "PI is a decent source" and the whole rune-server will come haunting you.
    Attached image
    Reply With Quote  
     

  12. #20  
    Registered Member
    Join Date
    May 2017
    Posts
    31
    Thanks given
    11
    Thanks received
    4
    Rep Power
    11
    Quote Originally Posted by Kris View Post
    I'm mistaken about what? The fact that it's a shitfest of a source?
    Just say the sentence "PI is a decent source" and the whole rune-server will come haunting you.
    Hahaha na lol. We started with this source entirely because its shit. We are want to rework the whole of the server.

    [EDIT] Mistaken about us write the construct code.

    Code:
    public static Player players[] = new Player[Settings.MAX_PLAYERS];
    	static {
    		for (int i = 0; i < Settings.MAX_PLAYERS; i++)
    			players[i] = null;
    	}
    Quote Originally Posted by Twisted bird View Post
    It’s going to take a bit more than changing how you store player objects, to get better performance in PI.
    We agree. This is only the start.
    Reply With Quote  
     

Page 2 of 3 FirstFirst 123 LastLast

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. PI exeption caught in array
    By youngy_james in forum Help
    Replies: 0
    Last Post: 02-17-2012, 01:34 AM
  2. [PI] Array to stop certain items from spawning
    By ....>§exy<.... in forum Help
    Replies: 10
    Last Post: 01-01-2012, 12:12 AM
  3. Replies: 20
    Last Post: 09-04-2011, 04:33 PM
  4. [PI] Array out of bounds, help
    By Beanerrr in forum Help
    Replies: 6
    Last Post: 04-24-2011, 11:04 PM
  5. Skillcape Arrays [REQ] Please [PI]
    By edgevillepkz in forum Help
    Replies: 0
    Last Post: 07-17-2010, 08:05 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
  •