Menu

How to detect changes?

Developers
Anonymous
2008-09-11
2013-06-06
  • Anonymous

    Anonymous - 2008-09-11

    How can I know when a new Zone is added/deleted? I'm mostly using the text client as an example but the only thing I see are players objects with the show world option. I expected to see Zone changes as well in the perception messages.

    Any idea?

     
    • Miguel Angel Blanch Lardin

      Does really clients need to know about new zones added?
      If clients do really really need that info, I would do it by creating an RPObject for world representation and adding events to that special object. There is really nothing similar on stendhal, as that object won't have any kind of game representation and it would be useful just to make client know about changes.

      Other option worth considering is to add the event to the player object itself if the number of zones added is small and the number of player that should notice it isn't big neither.

      Regards,
      Miguel

       
      • Anonymous

        Anonymous - 2008-09-11

        From your comment I understood that is not a good idea.

        It might not make sense for games like Stendahl but for mine it does since each zone is a "chat room" or a "match room". (I dunno how much do you remember about my wrestling game).

        That said, I use the event from previous posts at start of the client to ask for the list of rooms to populate on the client hoping that after that I would be able to capture the added or removed from the perception.

        But I was wrong.

        Room creation can be frequent since as suggested in old posts I should use a new Zone for each match cause each match can have it's own rules. Or is there a way of doing that in the server side without the zone creation?

         
        • Miguel Angel Blanch Lardin

          It is not exactly that it isn't a good idea, it is just that Marauroa was designed with a limited constant set of zones. Zones were just a abstract representation to limit the number of simultaneous players in an area.

          About your problem, you can work around the lack of zone creation/destroy notification by creating an special object that will notify clients about things like that.

          So on server you do.

          zone=new BlablablaZone()
          RPObject signaler=new Signal();
          zone.assignID(signaler);

          And now just extend RPWorld on add and remove zones so that it can obtain the signaler ( zone.getSignalObject()? ) of every other zone and you add an event to that objects with zone name and "add" or "remove" operation.
          It will suit your needs perfectly.

           
          • Anonymous

            Anonymous - 2008-09-13

            Here's what I've done so far:

            Created the RPObject:

            package games.jwrestling.server.core.engine;

            import marauroa.common.game.Definition;
            import marauroa.common.game.RPClass;
            import marauroa.common.game.RPObject;

            /**
            *
            * @author Javier A. Ortiz Bultron <javier.ortiz.78@gmail.com>
            */
            public class Signal extends RPObject {

                public Signal() {
                    setRPClass("signal");
                }

                /**
                 * Generates the RPClass and specifies slots and attributes.
                 */
                static void generateRPClass() {
                    RPClass signal = new RPClass("signal");
                    signal.isA("entity");
                    signal.addRPEvent("room_event", Definition.VOLATILE);
                }
            }

            Had to add the setRPClass call since the signal name was not assigned otherwise, dunno why...

            Modified my RPWOrld implementation:
            ...
                private void addZone(String name) {
                    if (getRPZone(name) == null) {
                        JwrestlingRPZone zone = new JwrestlingRPZone(name);
                        addRPZone(zone);
                    }
                }

                @Override
                public void addRPZone(IRPZone zone) {
                    super.addRPZone(zone);
                    JwrestlingRPZone jZone = (JwrestlingRPZone) getRPZone(((JwrestlingRPZone) zone).getName());
                    Signal signal = new Signal();
                    signal.addEvent(new RoomEvent(((JwrestlingRPZone) zone).getName(), RoomEvent.ADD));
                    jZone.addSignal(signal);
                    System.out.println(jZone.toString());
                }

                @Override
                public RPObject remove(ID zone) {
                    JwrestlingRPZone jZone = (JwrestlingRPZone) getRPZone(zone);
                    jZone.getSignal().addEvent(new RoomEvent(zone.getZoneID(), RoomEvent.ADD));
                    System.out.println(jZone.toString());
                    return super.remove(zone);
                }
            ...

            So I get the following when initializing the server (creating default zones):

            Configuring Log4J using marauroa/server/log4j.properties
            zone IRPZone.ID [id=Lobby] at (0,0) RPObject with Attributes of Class(signal):
            and RPSlots  and RPLink  and RPEvents [[room_event=Attributes of Class(): [action=add[room=Lobby]]]
            zone IRPZone.ID [id=Arena Entrance] at (0,0) RPObject with Attributes of Class(signal):  and RPSlots  and RPLink  and RPEvents [[room_event=Attributes of Class(): [action=add][room=Arena Entrance]]]
            INFO  [marauroad ] marauroad                (123 ) - marauroa is up and running.
            .. (startup time: 1.0 s)
            INFO  [marauroad ] Statistics               (123 ) - Total/Used memory: 7228/453
            3

            Great so far. But when I try to get that in the client (after creating a Zone from the client)

            zone IRPZone.ID [id=Test] at (0,0) RPObject with Attributes of Class(signal):  a
            nd RPSlots  and RPLink  and RPEvents [[room_event=Attributes of Class(): [action
            =add][room=Test]]]
            WARN  [verManager] RPServerManager          (208 ) - Turn duration overflow by 6
            491 ms:  0 0 6590 6590 6590 6590 6590 6590 6591 6591 6591

            The zone is created but can't capture that.

            What I'm missing? Do i I need to loop thru the players to add the event to them? That can be processing time consuming. How can I add that Signal to the normal perception being sent?

             
            • Miguel Angel Blanch Lardin

              Yep, you are missing that you need to iterate over all the zones signal object and add the event to it.
              Players will only recieve the object if they are already on the zone.

              A better approach ( if you expect players<zones ) would be to iterate players and add the event to them

               
              • Anonymous

                Anonymous - 2008-09-18

                In my case I expect amount of players to be >= zones. In the worst case one player per zone.

                I haven't tested but here's what I'm setting up to do.

                1. Added the signal to the SingletonRepository (so only one Signal object is used)
                2. Addding/deleting zones add the proper event to the repository signal.
                3. Extend the getPerception of the zones to add the signal to it.

                In theory it should work. I'm too tired to code today (just got out of work 14+ hours). I'll keep you posted with the results.

                Thanks for the great answer as always!

                 
                • Miguel Angel Blanch Lardin

                  Yes, that the idea but it won't work as you say.

                  Each RPObject store information useful to detect changes, so it won't work in the way you propose.
                  You need an unique signal object per zone.

                   
    • Anonymous

      Anonymous - 2008-09-19

      This might be a dumb question but is assigning invalid id as an object id the correct way of letting Marauroa assign an ID automatically?

      Something like setID(RPObject.INVALID_ID);

       
      • Miguel Angel Blanch Lardin

        No, the correct expected way is to call zone.assignID or something like that.

         
    • Anonymous

      Anonymous - 2008-09-19

      Ok, so I modified the approach to this:

      1. Added the events to the SingletonRepository (so only the events are created once)
      2. Addding/deleting zones add the proper event to the repository list.
      3. The zone's get perception updates it's signal object with the events on the repository and is added to the perception if the list size >0 (to avoid sending unnecessary objects)

      I thought that should work in theory but I found that I'm getting null objects in the Client. When I add the signal to the perception I print it out just to make sure it's not null and I get output like this:

      Adding signal: RPObject with Attributes of Class(signal): [id=-1][zoneid=] and R
      PSlots  and RPLink  and RPEvents [[room_event=Attributes of Class(): [action=add
      ][room=Lobby]]][[room_event=Attributes of Class(): [action=add][room=Arena Entra
      nce]]]

      So good so far.

      But in the client:

      Object modified-added: null <~~~~ This is the object.toString() result
      ERROR [Thread-0] Logger.java                   (68  ) - error in applyModifiedRPObjects
      java.lang.NullPointerException
              at games.jwrestling.client.jWrestlingClient$jWrestlingPerceptionListener.onModifiedAdded(jWrestlingClient.java:574)
              at marauroa.client.net.PerceptionHandler.applyPerceptionModifiedRPObjects(PerceptionHandler.java:248)
              at marauroa.client.net.PerceptionHandler.apply(PerceptionHandler.java:123)
              at games.jwrestling.client.jWrestlingClient.onPerception(jWrestlingClient.java:248)
              at marauroa.client.ClientFramework.loop(ClientFramework.java:540)
              at games.jwrestling.client.gui.jWrestlingScreen.gameLoop(jWrestlingScreen.java:356)
              at games.jwrestling.client.gui.j2DClient.gameLoop(j2DClient.java:65)
              at games.jwrestling.client.jwrestling.startGameGUI(jwrestling.java:106)
              at games.jwrestling.client.jwrestling.run(jwrestling.java:128)
      Java Result: -1

      Any idea?

      I'm just trying to see if I can catch the object:

      if(object.getRPClass().getName().equals("signal")){  <~~~ line 574
                      System.out.println("Got signal!");
                  }

       
      • Miguel Angel Blanch Lardin

        Why don't you create a SF project for your game and upload the code so I can have a look to the problem myself?.
        Anyway I think your problem is related to your previous query as an object with invalid id is being modified and so it can't be found when queried on client.

         
        • Anonymous

          Anonymous - 2008-09-19

          My project is on Sourceforge long ago. Just waiting for at least an alpha version to submit it to be added to the Marauroa games section.

          You can go: http://sourceforge.net/projects/jwrestling/

          You can checkout from the root. It has the code with the errors in the post.

          And before you say something, yes I still use Stendhal icons. I'm not good at graphics and I'm focused right now on making it work. Changing icons it's a lot faster/easier.

           
    • Anonymous

      Anonymous - 2008-09-20

      I just added this line for when the zone gets the signal for the first time:

      /**
           * @return the signal
           */
          public Signal getSignal() {
              if (signal == null) {
                  signal = new Signal();
                  assignRPObjectID(signal);
              }
              return signal;
          }

      Same result.

       
      • Miguel Angel Blanch Lardin

        I think you are not following me :)

        I mean you need a signal object per zone.
        So when you create a zone just assign it an id and add the signal object.

        After that just iterate all the zones to add the event about new zone created.

         
        • Anonymous

          Anonymous - 2008-09-20

          Each zone has it's own signal object. I just have the events in the repository and update each object.

           

Anonymous
Anonymous

Add attachments
Cancel