Package marauroa.server.game.rp
Class MarauroaRPZone
java.lang.Object
marauroa.server.game.rp.MarauroaRPZone
- Direct Known Subclasses:
StendhalRPZone
Default implementation of
The idea is to send only what changes of the objects that changed. This way we save even more bandwidth, making perceptions around 20% of the original delta perception size.
IRPZone
. This class implements the
Delta^2 algorithm to save bandwidth.
The idea behind the DPA is to avoid sending ALL the objects to a client each time, but only those that have been modified. Imagine that we have 1000 objects, and only Object 1 and Object 505 are active objects that are modified each turn.
The Traditional method: - Get objects that our player should see ( 1000 objects ) - Send them to player ( 1000 objects ) - Next turn - Get objects that our player should see ( 1000 objects ) - Send them to player - Next turn ...I hope you see the problem... we are sending objects that haven't changed each turn.
The delta perception algorithm: - Get objects that our player should see ( 1000 objects ) - Reduce the list to the modified ones ( 1000 objects ) - Store also the objects that are not longer visible ( 0 objects ) - Send them to player ( 1000 objects ) - Next turn - Get objects that our player should see ( 1000 objects ) - Reduce the list to the modified ones ( 2 objects ) - Store also the objects that are not longer visible ( 0 objects ) - Send them to player ( 2 objects ) - Next turn ...The next step of the delta perception algorithm is pretty clear: delta2
The idea is to send only what changes of the objects that changed. This way we save even more bandwidth, making perceptions around 20% of the original delta perception size.
The delta2 algorithm is based on four containers:
- List of added objects
- List of modified added attributes of objects
- List of modified deleted attributes of objects
- List of deleted objects
- Author:
- miguel
-
Nested Class Summary
Nested classes/interfaces inherited from interface marauroa.common.game.IRPZone
IRPZone.ID
-
Field Summary
Modifier and TypeFieldDescriptionprotected Map<RPObject.ID,RPObject>
Objects contained by the zone indexed by its id.protected IRPZone.ID
Name of the zone -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This method adds an object to this zone.void
assignRPObjectID(RPObject object)
This method assigns a valid id to the object.get(RPObject.ID id)
Returns the object which id is id.getID()
Returns the zoneidgetPerception(RPObject player, byte type)
Returns the perception of given type for that object.boolean
has(RPObject.ID id)
Returns true if the zone has that object.void
Hide an object from the perceptions, but it doesn't remove it from world.iterator()
Iterates over all the objects in the zone.void
This method notify zone that the object has been modified.void
nextTurn()
This method moves zone from this turn to the next turn.void
onFinish()
This method is called when the server finish to save the content of the zonevoid
onInit()
Load objects in database for this zone that were stored and waits for the database operation to complete.void
print(PrintStream out)
This method prints the whole zone.remove(RPObject.ID id)
Removes the object from zone.protected void
reset()
This methods resets the delta^2 information of objects.long
size()
This method returns the amount of objects in the zone.void
Store objects that has been tagged as storable to database asynchronously.void
Makes a hidden object to be visible again.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
zoneid
Name of the zone -
objects
Objects contained by the zone indexed by its id.
-
-
Constructor Details
-
MarauroaRPZone
Creates a new MarauroaRPZone- Parameters:
zoneid
- name of zone
-
-
Method Details
-
getID
Returns the zoneid -
onFinish
Description copied from interface:IRPZone
This method is called when the server finish to save the content of the zone -
storeToDatabase
public void storeToDatabase()Store objects that has been tagged as storable to database asynchronously. Note: This methods returns before the saving is completed. -
onInit
Load objects in database for this zone that were stored and waits for the database operation to complete. -
add
This method adds an object to this zone.- Specified by:
add
in interfaceIRPZone
- Parameters:
object
- object to add.- Throws:
RPObjectInvalidException
- if it lacks of mandatory attributes.
-
modify
This method notify zone that the object has been modified. You should call it only once per turn, even if inside the turn you modify it several times.- Specified by:
modify
in interfaceIRPZone
- Parameters:
object
- object to modify.- Throws:
RPObjectInvalidException
- if it lacks of mandatory attributes.
-
remove
Removes the object from zone. -
hide
Hide an object from the perceptions, but it doesn't remove it from world. Any further calls to modify will be ignored. -
unhide
Makes a hidden object to be visible again. It will appear on the perception as an added object. -
get
Returns the object which id is id. -
has
Returns true if the zone has that object. -
assignRPObjectID
This method assigns a valid id to the object.- Specified by:
assignRPObjectID
in interfaceIRPZone
- Parameters:
object
- the object that is going to obtain a new id
-
iterator
Iterates over all the objects in the zone. -
getPerception
Returns the perception of given type for that object.- Specified by:
getPerception
in interfaceIRPZone
- Parameters:
player
- object whose perception we are going to buildtype
- the type of perception:- SYNC
- DELTA
- Returns:
- the perception
-
reset
protected void reset()This methods resets the delta^2 information of objects. -
size
public long size()This method returns the amount of objects in the zone. -
print
This method prints the whole zone. Handle it with care.- Parameters:
out
- the PrintStream where zone is printed.
-
nextTurn
public void nextTurn()This method moves zone from this turn to the next turn. It is called by RPWorld.
-