Ejemplo n.º 1
0
 public static Actor example1() {
   Actor actor = new Actor();
   actor.setId(1);
   actor.setFName("Stephen");
   actor.setLName("Baldwin");
   return actor;
 }
Ejemplo n.º 2
0
  Collection<Actor> getObjectsAtPixel(int x, int y) {
    // This is a very naive and slow way of getting the objects at a given
    // pixel.
    // However, it makes sure that it doesn't use the collision checker
    // which we want to keep optimised.
    // It will be very slow with a lot of rotated objects. It is only used
    // when using the mouse to select objects, which is not a time-critical
    // task.

    List<Actor> result = new LinkedList<Actor>();
    TreeActorSet objects = getObjectsListInPaintOrder();
    for (Actor actor : objects) {
      Rect bounds = actor.getBoundingRect();
      if (x >= bounds.getX()
          && x <= bounds.getRight()
          && y >= bounds.getY()
          && y <= bounds.getTop()) {
        if (actor.containsPoint(x, y)) {
          result.add(actor);
        }
      }
    }

    return result;
  }
Ejemplo n.º 3
0
 public static Actor example5() {
   Actor actor = new Actor();
   actor.setId(5);
   actor.setFName("Tom");
   actor.setLName("Green");
   return actor;
 }
Ejemplo n.º 4
0
 public void mouseTouched(Actor actor, GGMouse mouse, Point spot) {
   switch (mouse.getEvent()) {
     case GGMouse.lPress:
       startLocation = toLocation(mouse.getX(), mouse.getY());
       actor.setOnTop();
       hotSpot = spot;
       break;
     case GGMouse.lDrag:
       Point imageCenter = new Point(mouse.getX() - hotSpot.x, mouse.getY() - hotSpot.y);
       actor.setPixelLocation(imageCenter);
       refresh();
       break;
     case GGMouse.lRelease:
       if (spot.x == -1) // Cursor is outside image
       actor.setLocation(startLocation);
       else {
         actor.setPixelLocation(new Point(mouse.getX(), mouse.getY()));
         nbMoves++;
         if (isOver()) setStatusText("Total #: " + nbMoves + ". Done.");
         else setStatusText("#: " + nbMoves);
       }
       actor.setLocationOffset(new Point(0, 0));
       hotSpot = null;
       refresh();
       break;
   }
 }
Ejemplo n.º 5
0
 public static Actor example3() {
   Actor actor = new Actor();
   actor.setId(3);
   actor.setFName("Drew");
   actor.setLName("Barrymore");
   return actor;
 }
Ejemplo n.º 6
0
 public static Actor example2() {
   Actor actor = new Actor();
   actor.setId(2);
   actor.setFName("Troy");
   actor.setLName("MacLure");
   return actor;
 }
Ejemplo n.º 7
0
  public void testTiming() {
    int c = 2;
    int b = 3;
    int p = 1;
    int t = 1;

    // int c = 1000000;
    // int b = 1;
    // int p = 4;
    // int t = 4;

    // burst size of 1
    // 4 parallel runs of 2000000 messages each.
    // 8000000 messages sent with 4 threads.
    // msgs per sec = 4020100
    // 249 nanoseconds per message
    // response time 996

    // int c = 10000;
    // int b = 1000;
    // int p = 4;
    // int t = 4;

    // burst size of 1000
    // 4 parallel runs of 20000000 messages each.
    // 80000000 messages sent with 4 threads.
    // msgs per sec = 42149631
    // 24 nanoseconds per message

    MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(t);
    try {
      Actor[] senders = new Actor[p];
      int i = 0;
      while (i < p) {
        Mailbox echoMailbox = mailboxFactory.createAsyncMailbox();
        Actor echo = new Echo(echoMailbox);
        echo.setInitialBufferCapacity(b + 10);
        Mailbox senderMailbox = mailboxFactory.createAsyncMailbox();
        if (b == 1) senders[i] = new Sender1(senderMailbox, echo, c, b);
        else senders[i] = new Sender(senderMailbox, echo, c, b);
        senders[i].setInitialBufferCapacity(b + 10);
        i += 1;
      }
      JAParallel parallel = new JAParallel(mailboxFactory.createAsyncMailbox(), senders);
      JAFuture future = new JAFuture();
      future.send(parallel, future);
      future.send(parallel, future);
      long t0 = System.currentTimeMillis();
      future.send(parallel, future);
      long t1 = System.currentTimeMillis();
      System.out.println("" + p + " parallel runs of " + (2L * c * b) + " messages each.");
      System.out.println("" + (2L * c * b * p) + " messages sent with " + t + " threads.");
      if (t1 != t0) System.out.println("msgs per sec = " + ((2L * c * b * p) * 1000L / (t1 - t0)));
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mailboxFactory.close();
    }
  }
Ejemplo n.º 8
0
  public String toString() {
    String toName;

    if (recipient != null) toName = recipient.getName();
    else toName = "all";

    return "From: " + sender.getName() + "\n" + "To: " + toName + "\n" + text + "\n";
  }
Ejemplo n.º 9
0
 public boolean checkCollision(Actor actor) {
   int actorX = actor.toPixel(actor.getX());
   int actorY = actor.toPixel(actor.getY());
   int dx = actorX - this.x;
   int dy = actorY - this.y;
   int dist = (int) Math.sqrt((double) (dx * dx + dy * dy));
   return dist <= this.r;
 }
Ejemplo n.º 10
0
 /**
  * If a target exist, status would appear above the target until the count down duration is 0. If
  * target is removed the status is removed as well.
  */
 public void act() {
   if (target != null) // if a target is assigned to a status
   {
     if (target.getWorld() != null) {
       setLocation(target.getX(), target.getY() - OFFSET); // offset myImage above the actor
       update(1); // update the image with the actual countdown(not controlled by keyboard)
     } else removeStatus(); // remove status along with actor
   }
 }
Ejemplo n.º 11
0
  /**
   * Removes an {@code Actor} from the {@code World}. The {@code Actor} must be both bound to this
   * {@code World} and not held by another {@code Actor}. However, if the {@code Actor} is expired,
   * it may always be removed.
   *
   * @param actor the {@code Actor} to be removed
   */
  public void removeActor(Actor actor) {
    Guard.argumentIsNotNull(actor);
    Guard.verifyState(actor.bound(this));
    Guard.verifyState(!actor.held() || actor.expired());

    unregisterActor(actor);
    removeFromGrid(actor);
    actor.setWorld(null);
  }
Ejemplo n.º 12
0
  @Transactional
  public void setupReferenceRelationship() {
    Node referenceNode = template.getReferenceNode();
    Actor bacon = actorRepository.findByPropertyValue("name", "Bacon, Kevin");

    if (bacon == null) throw new NoSuchElementException("Unable to find Kevin Bacon actor");

    referenceNode.createRelationshipTo(bacon.getPersistentState(), RelTypes.IMDB);
  }
Ejemplo n.º 13
0
 public boolean hasAtLeastOneActorThumbnail() {
   for (Actor currentActor : actors) {
     if (currentActor.getThumb() != null
         && currentActor.getThumb().getThumbURL() != null
         && !currentActor.getThumb().getThumbURL().equals("")) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 14
0
  public void step() {
    Grid<Actor> gr = getGrid();
    ArrayList<Actor> actors = new ArrayList<Actor>();
    for (Location loc : gr.getOccupiedLocations()) actors.add(gr.get(loc));

    for (Actor a : actors) {
      // only act if another actor hasn't removed a
      if (a.getGrid() == gr) a.act();
    }
  }
Ejemplo n.º 15
0
 public static Record systemConsole(String[] args) {
   // Not sure what the default value should be yet!!!
   Actor sysout = new Actor(null);
   Record data = new Record();
   data.put("out", sysout);
   data.put("args", fromStringList(args));
   Record console = new Record(data);
   sysout.start();
   return console;
 }
Ejemplo n.º 16
0
  public void tick() {
    for (Class<? extends Actor> cls : actOrder)
      for (Actor actor : getActors(cls)) {
        if (!actor.expired() && !actor.getClass().equals(Player.class)) {
          actor.act();
        }
      }

    removeExpired();
  }
Ejemplo n.º 17
0
  /**
   * Adds an {@code Actor} to the {@code World} at the specified location.
   *
   * @param actor the {@code World} being added
   * @param x the x location of the {@code Actor}
   * @param y the y location of the {@code Actor}
   */
  public void addActor(Actor actor, int x, int y) {
    Guard.argumentIsNotNull(actor);
    Guard.argumentsInsideBounds(x, y, width, height);
    Guard.verifyState(!actor.bound());
    Guard.verifyState(!actor.held());

    actor.setWorld(this);
    actor.setXY(x, y);
    addToGrid(actor);
    registerActor(actor);
  }
Ejemplo n.º 18
0
 @Override
 public void use(Actor actor) {
   actor.health += health;
   if (actor.health > actor.maxHealth) {
     actor.health = actor.maxHealth;
   }
   if (actor instanceof Player) {
     ((Player) actor).inventory.remove(this);
     ((Player) actor).updateHeldItem();
   }
 }
Ejemplo n.º 19
0
  public List<?> getBaconPath(final Actor actor) {
    if (actor == null) throw new IllegalArgumentException("Null actor");

    Actor bacon = actorRepository.findByPropertyValue("name", "Bacon, Kevin");

    Path path =
        GraphAlgoFactory.shortestPath(
                (PathExpander) StandardExpander.DEFAULT.add(RelTypes.ACTS_IN), 10)
            .findSinglePath(bacon.getPersistentState(), actor.getPersistentState());
    if (path == null) return Collections.emptyList();
    return convertNodesToActorsAndMovies(path);
  }
Ejemplo n.º 20
0
 /**
  * 添加角色到Layer(在Layer中添加的角色将自动赋予碰撞检查)
  *
  * @param object
  * @param x
  * @param y
  */
 public void addObject(Actor object, float x, float y) {
   if (isClose) {
     return;
   }
   synchronized (objects) {
     if (this.objects.add(object)) {
       object.addLayer(x, y, this);
       this.collisionChecker.addObject(object);
       object.addLayer(this);
     }
   }
 }
Ejemplo n.º 21
0
 public void mouseTouched(Actor actor, GGMouse mouse, Point pix) {
   if (!isMouseEnabled) return;
   if (nbTaken == 3) setStatusText("Take a maximum of 3. Click 'OK' to continue");
   else {
     agent.sendCommand(agentName, Command.REPORT_POSITION, actor.getLocation().x);
     actor.removeSelf();
     nbMatches--;
     setStatusText(nbMatches + " matches remaining. Click 'OK' to continue");
     nbTaken++;
     refresh();
   }
 }
Ejemplo n.º 22
0
  public void Update(boolean isRefresing) {
    // when we refresh the data from the internet, we load again episodes and we neew to get back
    // to the objects that already exists if the were viewed that is smth we have stored.
    if (IsSaved()) {
      ContentValues values = new ContentValues();
      // Then add the data, along with the corresponding name of the data type,
      // so the content provider knows what kind of value is being inserted.

      values.put(SeriesContract.SeriesEntry.COLUMN_NAME, name);
      values.put(SeriesContract.SeriesEntry.COLUMN_NETWORK, network);
      values.put(SeriesContract.SeriesEntry.COLUMN_POSTER_URL, poster_url);
      values.put(SeriesContract.SeriesEntry.COLUMN_BANNER_URL, image_url);
      values.put(SeriesContract.SeriesEntry.COLUMN_OVERVIEW, overView);
      values.put(SeriesContract.SeriesEntry.COLUMN_RATING, rating);
      values.put(SeriesContract.SeriesEntry.COLUMN_VOTES, votes);
      values.put(SeriesContract.SeriesEntry.COLUMN_REALSED_DATE, dateReleased);
      values.put(SeriesContract.SeriesEntry.COLUMN_GENRE, genre);
      values.put(SeriesContract.SeriesEntry.COLUMN_MODIFYDATE, modify_date.getTime());
      values.put(SeriesContract.SeriesEntry.COLUMN_STATUS, status);

      // Finally, insert serie data into the database.
      MyApplication.getContext()
          .getContentResolver()
          .update(
              SeriesContract.SeriesEntry.CONTENT_URI,
              values,
              SeriesContract.SeriesEntry.COLUMN_ID + "=?",
              new String[] {id});
      // The resulting URI contains the ID for the row.  Extract the locationId from the Uri.
      if (episodes != null && episodes.size() > 0) {
        List<Episode> list = episodes;
        for (Episode episode : list) {
          if (episode.IsSaved()) {
            episode.Update();
            if (isRefresing) {
              // we need to get back the field viewed from database to inflate it properly
              episode.LoadViewed();
            }
          } else episode.Save();
        }
      }
      if (actors != null && actors.size() > 0) {
        List<Actor> list = actors;
        for (Actor actor : list) {
          if (actor.IsSaved()) actor.Update();
          else actor.Save();
        }
      }
    } else {
      Save();
    }
  }
Ejemplo n.º 23
0
  /**
   * Add an Actor to the world (at the object's specified location).
   *
   * @param object The new object to add.
   * @throws IndexOutOfBoundsException If the coordinates are outside the bounds of the world.
   */
  public synchronized void addObject(Actor object, int x, int y) throws IndexOutOfBoundsException {
    // TODO bad performance when using a List for the objects. But if we
    // want to have paint order, a List is necessary.
    if (objects.contains(object)) {
      return;
    }

    object.addToWorld(x, y, this);

    collisionChecker.addObject(object);
    objects.add(object);

    object.addedToWorld(this);
  }
Ejemplo n.º 24
0
  /**
   * Method: getMoveLocations() Usage: 3rd step in act() of Critter ---------------------------- if
   * Follower has a target, Follower moves to the location opposite to the target's direction if
   * target is null, Follower roams like a generic Critter until a target is found @Postcondition:
   * The state of all actors is unchanged.
   *
   * @return a list of possible locations for the next move
   */
  public ArrayList<Location> getMoveLocations() {
    ArrayList<Location> nextLoc = new ArrayList<Location>();

    if (target != null) {
      Location next =
          target.getLocation().getAdjacentLocation(target.getDirection() + Location.HALF_CIRCLE);
      if (getGrid().isValid(next)) nextLoc.add(next);
    } else {
      for (Location l : super.getMoveLocations()) // for every empty adjacent loc
      if (getGrid().isValid(l)) // if it's also valid
        nextLoc.add(l); // add it to list of possible locs
    }

    return nextLoc;
  }
Ejemplo n.º 25
0
  public Actor deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException {

    Actor actor = new Actor();
    if (json.isJsonPrimitive()) {
      actor.login = json.getAsJsonPrimitive().getAsString();
    } else {
      JsonObject jsObj = json.getAsJsonObject();
      JsonElement login = jsObj.get("login");
      if (login != null) {
        actor.login = login.getAsString();
      }
    }
    return actor;
  }
Ejemplo n.º 26
0
  public static Actor example4() {
    // include in populate
    Film film = new Film();
    film.setName("Scream 4");
    film.setDescription("Scream 3 was the last one!  What's going on?");
    film.setDuration(new java.math.BigDecimal(2));

    Actor actor = new Actor();
    actor.setId(4);
    actor.setFName("Nev");
    actor.setLName("Campbell");

    film.addActor(actor);
    return actor;
  }
Ejemplo n.º 27
0
  /**
   * Returns every tile that is visible at a given location, ordered such that the tile with highest
   * priority (the tile returned by look) is first, and the lowest priority is last. This last tile
   * will be the face of the actual tile itself. Note that any actor which has a null face will not
   * be included.
   *
   * @param x the x value of the location being queried
   * @param y the y value of the location being queried
   * @return every tile that is visible at a given location
   */
  public List<ColoredChar> lookAll(int x, int y) {
    Guard.argumentsInsideBounds(x, y, width, height);

    List<ColoredChar> look = new ArrayList<ColoredChar>();

    for (Class<? extends Actor> cls : drawOrder)
      for (Actor actor : getActorsAt(cls, x, y)) {
        ColoredChar face = actor.face();
        if (face != null) look.add(actor.face());
      }

    look.add(tileAt(x, y));

    return look;
  }
Ejemplo n.º 28
0
 private final void run(
     String name, ActorFactory factory, Mailbox mailbox, FutureValue<Object> future) {
   Thread.currentThread().setName(name);
   Actor actor;
   try {
     actor = factory.newActor(name, mailboxes);
     assert null != actor;
   } catch (final Throwable t) {
     future.setException(t);
     return;
   }
   future.set(null);
   mailbox.activate();
   actor.run(mailbox);
 }
Ejemplo n.º 29
0
 /**
  * Method: makeMove() Usage: last step in act() of Critter
  * ------------------------------------------- Follower faces the same way target is and steps are
  * incremented, if target is null, it faces the direction it just moved in then calls Critters
  * makeMove to go to the new location @Postcondition: (1) <code>getLocation() == loc</code>. (2)
  * The state of all actors other than those at the old and new locations is unchanged.
  *
  * @param loc the location to move to
  */
 public void makeMove(Location loc) {
   if (target != null) {
     setDirection(target.getDirection());
     steps++;
   } else setDirection(getLocation().getDirectionToward(loc));
   super.makeMove(loc);
 }
  @Override
  public void tick(int tickcount) {
    super.tick(tickcount);
    int keyspressed = 0;
    int keysjustpressed = 0;
    if (Gdx.input.isKeyPressed(this.UPKEY)) keyspressed |= 0b00000001;
    if (Gdx.input.isKeyPressed(this.DOWNKEY)) keyspressed |= 0b00000010;
    if (Gdx.input.isKeyPressed(this.LEFTKEY)) keyspressed |= 0b00000100;
    if (Gdx.input.isKeyPressed(this.RIGHTKEY)) keyspressed |= 0b00001000;
    if (Gdx.input.isKeyPressed(this.AKEY)) keyspressed |= 0b00010000;
    if (Gdx.input.isKeyPressed(this.BKEY)) keyspressed |= 0b00100000;
    if (Gdx.input.isKeyPressed(this.XKEY)) keyspressed |= 0b01000000;
    if (Gdx.input.isKeyPressed(this.YKEY)) keyspressed |= 0b10000000;

    if (Gdx.input.isKeyJustPressed(this.UPKEY)) keysjustpressed |= 0b00000001;
    if (Gdx.input.isKeyJustPressed(this.DOWNKEY)) keysjustpressed |= 0b00000010;
    if (Gdx.input.isKeyJustPressed(this.LEFTKEY)) keysjustpressed |= 0b00000100;
    if (Gdx.input.isKeyJustPressed(this.RIGHTKEY)) keysjustpressed |= 0b00001000;
    if (Gdx.input.isKeyJustPressed(this.AKEY)) keysjustpressed |= 0b00010000;
    if (Gdx.input.isKeyJustPressed(this.BKEY)) keysjustpressed |= 0b00100000;
    if (Gdx.input.isKeyJustPressed(this.XKEY)) keysjustpressed |= 0b01000000;
    if (Gdx.input.isKeyJustPressed(this.YKEY)) keysjustpressed |= 0b10000000;

    this.processInput(keyspressed, keysjustpressed);
  }