Jump to content

Recommended Posts

Posted (edited)

Alright as title says. Let's say we got an xml and we want to store objects which is a range of type. 

int[], ArrayLists, Strings e.t.c

 

Known ways:

 

1. Create ex. FastMap into FastMaps such as  FastMap<Integer, FastMap<String, int[]>>

which is complicated to put and retrieve objects.

 

2. Stats sets that contain other stats sets. We can add one statset into another and make a tree

 

Is there any other way and more efficient in order load items from xmls and  store them?

 

Ps. i would prefer an experienced person with java structure to answer and give other solutions that really make it easier and more dynamic.

Thanks

Edited by AccessDenied
Posted (edited)

A StatSet is nothing more than a extended HashMap with more methods, allowing you for a String key to retrieve any type of object. It allows easy fill on loading, for the cost of overhead. A StatSet shouldn't really be used because of the overhead generated by String key. You could for example move every single variable from L2PcInstance into a single StatsSet (which will allow you to drop every single getter and setter). Will you do it, knowing that you must .get( the Map when you could simply retrieve the correct boolean/int/String by yourself with a getter if that was written normally ? I don't think so.

 

Also, a FastMap got no use at all to load static data, you both don't need the potential concurrency from .shared(true), nor the ordered system. You just create overhead for nothing using a FastMap.

 

The proper way is to create you own class defining the object similar to... Everything else :P. For example, Castle is an object, filled by database on startup. On aCis I recently moved hardcoded or SQL data related to static stuff to XML, but basically the Castle object is filled with int, List<MercenaryTicket>, List<Integer>, etc etc...

 

So long answer short, create your own Object class holding properties, then either use a StatsSet to feed that object or put every single parameters in the constructor :

public class Castle
{
     int _castleId;
     String _name;

     // By feeding each parameters into constructor
     public Castle(int id, String name)
     {
          _castleId = id;
          _name = name;
     }


     // By feeding using a StatsSet
     public Castle(StatsSet data)
     {
          _castleId = data.getInteger("castleId");
          _name = data.getString("name");
     }
}

Obviously StatsSet is just more readable when you got 10, 15, 20 parameters to pass on the godamn constructor.

 

You can also feed your object using public setter. As you can see, the castle exemple simply got 2 properties when it normally got billions other (artifact id, circlet, list of mercenary tickets,...). The XML handles that scenario when parsing the XML :

...
if ("artifact".equalsIgnoreCase(cat.getNodeName()))
	castle.setArtifacts(cat.getAttributes().getNamedItem("val").getNodeValue());
...

And then, on Castle object :

public void setArtifacts(String idsToSplit)
{
	for (String idToSplit : idsToSplit.split(";"))
		_artifacts.add(Integer.parseInt(idToSplit));
}

That scenario is right for anything :

- ArmorSetTable uses ArmorSet as storage object.

- FishTable uses FishData

- CastleManager uses Castle

etc etc.

 

On aCis and latest L2J, you also have generic holders such as IntIntHolder which avoid to generate your own class but simply retrieve it from a id/value. IntIntHolder is useful to store skillId, skillLevel or itemId, price. Beware, IntIntHolder is still an object to create - it simply avoids you to write your own little inner classes when you need only to store a paired int/int.

Edited by Tryskell
Posted

A StatSet is nothing more than a extended HashMap with more methods, allowing you for a String key to retrieve any type of object. It allows easy fill on loading, for the cost of overhead. A StatSet shouldn't really be used because of the overhead generated by String key. You could for example move every single variable from L2PcInstance into a single StatsSet (which will allow you to drop every single getter and setter). Will you do it, knowing that you must .get( the Map when you could simply retrieve the correct boolean/int/String by yourself with a getter if that was written normally ? I don't think so.

 

Also, a FastMap got no use at all to load static data, you both don't need the potential concurrency from .shared(true), nor the ordered system. You just create overhead for nothing using a FastMap.

 

The proper way is to create you own class defining the object similar to... Everything else :P. For example, Castle is an object, filled by database on startup. On aCis I recently moved hardcoded or SQL data related to static stuff to XML, but basically the Castle object is filled with int, List<MercenaryTicket>, List<Integer>, etc etc...

 

So long answer short, create your own Object class holding properties, then either use a StatsSet to feed that object or put every single parameters in the constructor :

public class Castle
{
     int _castleId;
     String _name;

     // By feeding each parameters into constructor
     public Castle(int id, String name)
     {
          _castleId = id;
          _name = name;
     }


     // By feeding using a StatsSet
     public Castle(StatsSet data)
     {
          _castleId = data.getInteger("castleId");
          _name = data.getString("name");
     }
}

Obviously StatsSet is just more readable when you got 10, 15, 20 parameters to pass on the godamn constructor.

 

You can also feed your object using public setter. As you can see, the castle exemple simply got 2 properties when it normally got billions other (artifact id, circlet, list of mercenary tickets,...). The XML handles that scenario when parsing the XML :

...
if ("artifact".equalsIgnoreCase(cat.getNodeName()))
	castle.setArtifacts(cat.getAttributes().getNamedItem("val").getNodeValue());
...

And then, on Castle object :

public void setArtifacts(String idsToSplit)
{
	for (String idToSplit : idsToSplit.split(";"))
		_artifacts.add(Integer.parseInt(idToSplit));
}

That scenario is right for anything :

- ArmorSetTable uses ArmorSet as storage object.

- FishTable uses FishData

- CastleManager uses Castle

etc etc.

 

On aCis and latest L2J, you also have generic holders such as IntIntHolder which avoid to generate your own class but simply retrieve it from a id/value. IntIntHolder is useful to store skillId, skillLevel or itemId, price. Beware, IntIntHolder is still an object to create - it simply avoids you to write your own little inner classes when you need only to store a paired int/int.

 

 

First of all thanks for being serious. Afcourse Sset is more readable by user when you play with 10 different objects and variables example to store an Event Data which require let's say

1. team color (FastMap)

2. team name (FastMap)

3. map data which contain team position (FastMap into FastMap)

 

e.t.c and i don't know how many more variables can you store but since i made an event and i'm using FastMaps to store objects after 4 fastMaps it kinda start getting ridiculously hard. I mean only the idea

get(x).get(x).get(x).get(x) after 5 times it kill my brain.

 

Also i'm not really familiar when it come in Statset to load from xml. Everytime you load data from xml you have plenty of options and if they exist since you're using

 

 

 

if ("artifact".equalsIgnoreCase(cat.getNodeName()))

 

so since we don't know how many variables are loaded we can't set the statset. Maybe is complicated in my head thats why i asked any alternative idea. I want avoid making different classes

to make objects, i want keep all in 1 class and all in 1 method and make a simple style like    xxxx.getEvent(1).getData().getEventMap(1).getPositionForTeam(1); or something simple like that to avoid the 

mess i have right now with different classes. The idea behind this is to make a statsset that as you said extends HMs and contain other elements or other statsets inside if i'm right. The idea is pretty much easy.

I don't really want an example or anything i just wanted to know if the way i mention is better to be done with Sset or any other way in order to avoid making different classes and keep all in 1. 

 

Thanks again.

Posted

Are you trolling again or what? :lol:

No i'm actualy asking advice of someone more experienced to tell me if is ok to continue the idea i mentionted with the Sset or what. 

No searching for solution or examples just a yes or no and if is fine.

Posted

I answered you, StatsSet generates a overhead where basic properties don't. StatsSet should be kept only for data feeding.

 

And you obviously know what data you are loading for a raw stuff like Event. If you got a followup of get.get.get, it simply shows how terrible you structured your stuff. That's the sort of stuff to think BEFORE coding it.

 

An Event class probably has :

- int _id

- String _description

- List<L2PcInstance> _players

- List<Location> (or SpawnLocation) _spawnPoints

 

A Team class (can be edited for an extended enum) is different than a Event class. Don't melt everything. It probably has :

- int _id

- String _name

- int _color

 

etc etc.

Posted

It really depends what you want to do.

What should be taken into consideration:

- If object will change in time or loaded just once

- If it will be changed from multiple threads at the time

- How long(size, length) is it going to be

- What kind of access to it you want to have. It will be just fully iterated often, get(x), maybe you just want to take first index and then remove it?

 

Don't use FastList just because it is "fast".

 

If you want to load data from xml, i strongly suggest simple array(or obviously arrayList which might be later .trimToSize()).

 

Don't make FastMap<Integer, FastMap<String, int[]>>

Make:

ArrayList<MyContainer>();

class MyContainer
{
    private final int id;
    private final List<MySecondContainer> importantNameHere;
}

class MySecondContainer
{
    private final int String nameMaybe;
    private final int[] someKindOfData;
}

Thats most secure way.

- How long(size, length) is it going to be

Posted (edited)

It really depends what you want to do.

What should be taken into consideration:

- If object will change in time or loaded just once

- If it will be changed from multiple threads at the time

- How long(size, length) is it going to be

- What kind of access to it you want to have. It will be just fully iterated often, get(x), maybe you just want to take first index and then remove it?

 

Don't use FastList just because it is "fast".

 

If you want to load data from xml, i strongly suggest simple array(or obviously arrayList which might be later .trimToSize()).

 

Don't make FastMap<Integer, FastMap<String, int[]>>

Make:

ArrayList<MyContainer>();

class MyContainer
{
    private final int id;
    private final List<MySecondContainer> importantNameHere;
}

class MySecondContainer
{
    private final int String nameMaybe;
    private final int[] someKindOfData;
}

Thats most secure way.

- How long(size, length) is it going to be

 

Yeap kinda trying to make it like this

private final FastMap<Integer, ArrayList> _mapLocation = new FastMap<Integer, ArrayList>().shared();
	
	private class MapData
	{
		private String _mapName;
		private FastMap<Integer, ArrayList> mapLocation;
		
		private MapData(String mapName, FastMap<Integer, ArrayList> list)
		{
			_mapName = mapName;
			mapLocation = list;
		}
		
		public ArrayList getMapLocationByOwner(String owner)
		{
			ArrayList list = _mapLocation.get(owner);
			return list;
		}
		
		public String getMapName()
		{
			return _mapName;
		}
	}
	
	/**
	 * 
	 * @param id
	 * @return Selected map base on input id
	 */
	public MapData getMapById(int id)
	{
		if (_mapData.containsKey(id))
			return _mapData.get(id);
		else
			System.out.print("Error trying get null MAP");
		
		return null;
	}

Thats why i did until now but still is a bit fucked up..

 

And in ArrayList imma put HashMaps tho. Ps ignore the "_mapLocation.get(owner);"

Edited by AccessDenied
Posted

First of all, those locations are going to be just loaded and stay the same until server or xml restart yes? Then you dont need to make them .shared().

If you dont need shared, why bother to use FastMap at all, it is better to use HashMap.

 

Since you are querying the data by just .get(ID), map will be faster than list or set or other collections. 

You should notice that Map<Integer, something> creates Integer object for each record. Integer is not the same as int, it takes far more memory. If you have small collection, thats fine, why would we care. If you have big collection like all items, thats big deal.

Also in getMapById(int) int is cast to Integer, it takes additional time, but thats fine. You might use .getOrDefault in there, takes just 1 line.

 

ArrayList thing in MapData i skip.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




  • Posts

    • Changeset 411 (3596)   ZoneManager, Manors, Cursed Weapon, AI, Bugfixes, Organization   [Fishing is currently malfunctioning. Wait next revisions for item/skills reparse + fish rework.   ZoneManager - Ty Bandnentans for the backup job Rework ZoneManager, parsing L2OFF zones and associated parameters. Zones are now handled by name, and not anymore by custom, dynamic, id - making them easier to invoke, and allowing retail script to invoke them aswell. Zones are now extending Territory, and don't use anymore shapes (Circle/Rectangle/NPoly). Default shape is Polygon, cut into Triangles, through Territory. One more step down to delete "zone.form" package and ZoneForm class. All zone types are added as L2OFF. Custom zone types are deleted (ARTIFACT, SCRIPT,...) and good names are provided (Boss = NoRestart, NoLanding = NoFly, etc). NoRestart zones type (eg. previous Boss) behavior is now matching retail, and uses retail parameters aswell. It normally fixes the "instant teleport back to town when entering boss zones through few teleporters" issue. Implementation of onLogin/onLogout/onEnterRegion/onExitRegion methods types for zones. Implementation of EffectZoneTaskManager (a universal 666ms ticking task for all effect zones) and ZoneRevalidationTaskManager (a universal 666ms Creature revalidateZone task, avoiding multiple calls). Migrate zone related Stat Func application to zone onEnter/onExit, deleting ZoneManager#getZone calls upon stat calculation (run speed, hp/mp regen). Fix moving from same zone type to same zone type ; it doesn't consider to going out (hotfix). Should notably fix water re-entrance issue. Delete custom CastleTeleportZone, use retail Mass Teleporter HTMs and AI params. Manors - Ty LaRoja for fixes Fix an issue where turning in crops to the Manor Lord for materials would incorrectly add adena to the castle vault instead of deducting it, while seed sales are correctly handled. Fix an issue where the "Stop Purchase" button did not properly clear all crops. The last crop would remain set, and the manor wouldn't fully disable unless all adena was manually removed from the vault. Introduce //manor [change], allowing manually a manor cycle to run. Cursed Weapon CW passive skill is properly cleaned up. Ty Denzel for report. Don't store anymore Player reference on CursedWeapon. Store CursedWeapon reference upon Player, rather than itemId - for faster acquisition. Fix a NPE upon CursedWeapon#endOfLife. AI Fix aggressive monsters behavior. Ty Denzel for report, Bandnentans for fix. Fix EvilateA/B not respawning demons. Ty Bandnentans for report. Fix a conditional NPE over PartyLeaderHeretic2Aggressive AI. Fix Gordon script NPE. Ty Sahar for report. Move most DefaultNpc methods to Npc (npc isn't a parameter anymore, but the method caller). Overload NpcAi#addCastDesire with NpcSkillType parameter, since it was hard to read and error-prone. -> npc.getAI().addCastDesire(attacker, getNpcSkillByType(npc, NpcSkillType.DD_MAGIC), 1000000); -> npc.getAI().addCastDesire(attacker, NpcSkillType.DD_MAGIC, 1000000);. Implement NpcMaker#areaSetOnOff and Npc#areaSetOnOff. AIs can now activate and de-activate areas based on behavior (generally spawn and dying). Uncomment all scripts areas triggers. Implement Creature#isInThisTerritory, checking if a Creature is in a parametrized zone name. Uncomment all scripts areas triggers. Re-introduce back RandomAnimationTaskManager for Folks. Ty Bandnentans for report. getSeeRange() is now minimal Config.DEFAULT_SEE_RANGE - can't be lower - notably fix Gordon ON_SEE event. Implement NODE_ARRIVED EventHandler. Fix Gordon continuously running after attacking someone. Bugfixes Sanitize the username string in AuthLogin as it is in RequestAuthLogin. Ty artemis for fix. //set title is fixed (allows more than one token, and spaces between words). Add the possibility to clear title with no parameter. Add a missing sysMessage upon regular Pet's name set, remove one check processed by regex (and which had invalid sysMessage). Fix a "day 1" issue related to CH : if your clan was holding any CH, HP/MP regen was applied no matter the CH zone you were currently set. Remove run stance upon Npc#reduceCurrentHp, making Walker run when being hit. Ty Denzel for report. Fix an issue where Castle owners couldn't register for SCH. Fix the related SystemMessageId. Allow blocked interaction to scan at higher range. Organization Config : Introduce NAME_REGEX_PATTERN and TITLE_REGEX_PATTERN, delete ZONE_TOWN Config. Territory "Polygon to Triangle" algorithm is edited for an adapted version of Earcut (earcut4j without the hole handling), allowing monotone polygon and using Z-order curve index for faster spatial partitioning. Rewrite Triangle#intersects method to be more accurate. Drop grandboss_list SQL. The few "var" are now named "variable", prior to var keyword addition in Java. Update MariaDB connector from 3.1.4 to 3.5.3. Add //set pvp <number> and //set pk <number>. RoomInfo improvement - allocate and reuse a single List, rather than nullify it and create a new one.
    • any mod can change the title 'Rules' and move to the  marketplace? @Maxtor
    • One thing i want to add  is disabling root login, creating a new user with sudo privileges, setting up SSH key authentication and completely disabling password  logins and also avoid  exposure on port 80 completely. it's much better to manage them directly from your local machine using IP whitelisting on database user or firewall-iptables. This way, only trusted IPs have access. Even better ssh tunnel. Good job though. 
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock