Class Perception

java.lang.Object
marauroa.common.game.Perception

public class Perception extends Object
The Perception class provides a encapsultated way of managing perceptions. It is the core implementation of the Delta^2. Perception manages added, modified and removed perceptions. The basic structure for sending world updates to clients is called perceptions. There are two types of perception:
  • Sync perceptions
    these are used to synchronize clients with the server world representation. This is the only valid way of knowing world's status.
  • Delta perception
    this is used to send only the changes to the world since the last perception.
Our actual Perception system is called Delta2. It is heavily attached to the Marauroa core, so I recommend you to use it :)

How Perceptions and Actions work Actions are sent from the client to the server in order to make the character perform an action. In order for the client to know the result of the action the Server needs to send a reply to the client. How will this be done?

In a first attempt, we send clients back an action that was the result of their action. However, this made the code really hard because we had to update two different things, perceptions and actions. Instead the solution appears intuitively: Why not join action reply and perceptions.

So the action reply is stored inside each object (that executed the action ) with a set of attributes that determine the action return status and the attributes. This way of doing replys makes it a bit harder on RPManager but it simplifys the creation of new clients alot.

See RPAction reply in the RPObject documentation to know exactly what is returned. However, keep in mind that the return result depends of each particular game.

Author:
miguel
  • Field Details

    • DELTA

      public static final byte DELTA
      A Delta perception sends only changes
      See Also:
      Constant Field Values
    • SYNC

      public static final byte SYNC
      A sync perception sends the whole world
      See Also:
      Constant Field Values
    • type

      public byte type
      The type of the perception: Delta or Sync
    • zoneid

      public IRPZone.ID zoneid
      The zone.id to which this perception belong
    • addedList

      public List<RPObject> addedList
      The added objects
    • modifiedAddedList

      public List<RPObject> modifiedAddedList
      The modified added objects
    • modifiedDeletedList

      public List<RPObject> modifiedDeletedList
      The modified deleted objects
    • deletedList

      public List<RPObject> deletedList
      The deleted objects
  • Constructor Details

    • Perception

      public Perception(byte type, IRPZone.ID zoneid)
      Constructor
      Parameters:
      type - the type of perception, either Delta or Sync perception.
      zoneid - the zone we are building the perception for.
  • Method Details

    • added

      public void added(RPObject object)
      This method adds an added object to the perception
      Parameters:
      object - the object added.
    • modified

      public void modified(RPObject modified) throws Exception
      This method adds an modified object of the world
      Parameters:
      modified - the modified object
      Throws:
      Exception - if there is any problem computing the differences.
    • removed

      public void removed(RPObject object)
      This method adds a removed object of the world
      Parameters:
      object - the removed object
    • size

      public int size()
      Returns the number of elements of the perception
      Returns:
      the amount of objects
    • clear

      public void clear()
      Clear the perception
    • toString

      public String toString()
      Overrides:
      toString in class Object