Marauroa 3.8: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Hendrik Brummermann |
imported>Hendrik Brummermann No edit summary |
||
| (44 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{Navigation for Marauroa Top}} |
|||
{{Navigation for Marauroa General}} |
|||
There are a number of small new features in Marauroa 3.8 that will be explained on this page. |
There are a number of small new features in Marauroa 3.8 that will be explained on this page. |
||
| Line 41: | Line 44: | ||
; Reason for change : There are many kinds of map like data structures in Stendhal (buddy list, ignore list, quest states, visited zones, ...). The previous way of using an RPSlot with exactly one RPObject was inconvenient. |
; Reason for change : There are many kinds of map like data structures in Stendhal (buddy list, ignore list, quest states, visited zones, ...). The previous way of using an RPSlot with exactly one RPObject was inconvenient. |
||
; Impact on Marauroa users : There are new methods in RPObject to work with the maps |
; Impact on Marauroa users : There are new methods in RPObject to work with the maps |
||
; Details : To use a map attribute you need to define an attribute with type map in the RPClass. It is done the same way as ''normal'' attributes for Strings or Integers. Here a short example on how to define a map attribute as it is done in Stendhal for the buddy list: |
|||
; Details : todo |
|||
player.addAttribute("buddies", Type.MAP, Definition.PRIVATE); |
|||
Afterwards you can access the map with several methods defined in RPObject to put or get values. To put a key value pair in a certain map you need to call the put method for maps: |
|||
rpobject.put(mapname, key, value); |
|||
To get a value stored for a key in a map you need to use the get method for maps: |
|||
rpobject.get(mapname, key); |
|||
The put and get methods provide methods to store/access String, Integer and Boolean values like they are provided for the existing attributes. |
|||
public void put(String mapname, String key, String value) |
|||
public void put(String mapname, String key, int value) |
|||
public void put(String mapname, String key, boolean value) |
|||
public String get(String mapname, String key) |
|||
public int get(String mapname, String key) |
|||
public boolean get(String mapname, String key) |
|||
If you need to check if a certain map is present in a RPObject you can to this by calling |
|||
rpobject.hasMap(mapname) |
|||
It returns true if within the RPObject has a map with mapname and false if not. |
|||
To access the map as a whole thing it is possible to obtain a copy via the getMap method. |
|||
Map<String, String> theWholeMap = rpobject.getMap(mapname); |
|||
As a convenience method RPObject can return all maps put together in one map: |
|||
public Map<String, Map<String, String>> maps() |
|||
An example usage of the maps can be found in the [http://arianne.cvs.sourceforge.net/viewvc/arianne/stendhal/src/games/stendhal/server/entity/player/Player.java?revision=1.284.2.1&view=markup Player] class of [[Stendhal]]. The buddies and their online statusses of a player are stored as a map within the player object. The class [http://arianne.cvs.sourceforge.net/viewvc/arianne/stendhal/src/games/stendhal/server/entity/player/PlayerRPClass.java?revision=1.164&view=markup PlayerRPClass] shows how to define a map attribute in a RPClass. |
|||
== Performance optimization == |
== Performance optimization == |
||
| Line 47: | Line 79: | ||
; Summary : Login events are now processed asynchronously |
; Summary : Login events are now processed asynchronously |
||
; Reason for change : On login a number of database queries have to be done and some of them are relatively slow (up to 100ms) so this slowed down turn execusion. |
; Reason for change : On login a number of database queries have to be done and some of them are relatively slow (up to 100ms) so this slowed down turn execusion. |
||
; Impact on Marauroa users : |
; Impact on Marauroa users : No changes required |
||
; Details : On login Marauroa has to verify the username and password and check if the account was banned. In addition to that it checks if the account was blocked because of too many failed login attempts. And if all is well, it loads a list of all characters belonging to that account, including character details. All in all this can take up to 100ms on a large database with many logged login events. |
; Details : On login Marauroa has to verify the username and password and check if the account was banned. In addition to that it checks if the account was blocked because of too many failed login attempts. And if all is well, it loads a list of all characters belonging to that account, including character details. All in all this can take up to 100ms on a large database with many logged login events. |
||
: Although login events have always been outside the normal turn loop, they used a common synchronization lock. In Marauroa 3.8 all of this happens without holding the lock. Only the small and very fast step of placing a selected character into the world is synchronized. |
: Although login events have always been outside the normal turn loop, they used a common synchronization lock. In Marauroa 3.8 all of this happens without holding the lock. Only the small and very fast step of placing a selected character into the world is synchronized. |
||
| Line 59: | Line 91: | ||
; Details : I was wondering why Marauroa is so much faster on Marboard with 100,000 objects and a turn time of 30ms than it is in Stendhal with less objects and a turn time of 300ms. Using a profiler it turned out that a deeply nested inheritance hierarchy slows down calls to RPObject.get() and RPObject.put(). Those calls need to find the attribute definition (get() because of static attributes and put() in order to validate the datatype). And Stendhal does a huge amount of get()s and put()s every turn. |
; Details : I was wondering why Marauroa is so much faster on Marboard with 100,000 objects and a turn time of 30ms than it is in Stendhal with less objects and a turn time of 300ms. Using a profiler it turned out that a deeply nested inheritance hierarchy slows down calls to RPObject.get() and RPObject.put(). Those calls need to find the attribute definition (get() because of static attributes and put() in order to validate the datatype). And Stendhal does a huge amount of get()s and put()s every turn. |
||
: Baking a class is similar to baking a cake: After you have thrown in all the ingredients, the cake is baked which causes the ingredients to melt together. In Marauroa: After all the attributes are defined in the inheritance hierarchy, baking means that the attribute of parent classes are melted into the child classes. Just like you cannot take the eggs out of a baked cake, further changes to attributes are not visible in child classes. |
: Baking a class is similar to baking a cake: After you have thrown in all the ingredients, the cake is baked which causes the ingredients to melt together. In Marauroa: After all the attributes are defined in the inheritance hierarchy, baking means that the attribute of parent classes are melted into the child classes. Just like you cannot take the eggs out of a baked cake, further changes to attributes are not visible in child classes. |
||
{{#breadcrumbs: [[Marauroa]] | [[Marauroa|Overview]] | [[Marauroa 3.8|Marauroa 3.8]] }} |
|||