[gee-svn] SF.net SVN: gabel: [189] trunk/gee/src/java/edu/indiana/psych/gee
Status: Alpha
Brought to you by:
alllee
|
From: <al...@us...> - 2006-06-18 22:51:50
|
Revision: 189 Author: alllee Date: 2006-06-18 15:51:45 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/gabel/?rev=189&view=rev Log Message: ----------- adding new subject/self/food images to GridView, still need to hook in extra directions.. Modified Paths: -------------- trunk/gee/src/java/edu/indiana/psych/gee/AbstractExperiment.java trunk/gee/src/java/edu/indiana/psych/gee/forager/GridView.java trunk/gee/src/java/edu/indiana/psych/gee/forager/client/DebriefingView.java trunk/gee/src/java/edu/indiana/psych/gee/forager/client/ForagerClient.java trunk/gee/src/java/edu/indiana/psych/gee/forager/client/ForagerClientGameState.java trunk/gee/src/java/edu/indiana/psych/gee/forager/client/SubjectView.java trunk/gee/src/java/edu/indiana/psych/gee/net/NioDispatcher.java Modified: trunk/gee/src/java/edu/indiana/psych/gee/AbstractExperiment.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/AbstractExperiment.java 2006-06-18 18:34:40 UTC (rev 188) +++ trunk/gee/src/java/edu/indiana/psych/gee/AbstractExperiment.java 2006-06-18 22:51:45 UTC (rev 189) @@ -85,6 +85,7 @@ else { getLogger().warn("Ignoring spurious request to STOP: " + toString()); } + getEventChannel().remove(this); } public int getServerPort() { Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/GridView.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/GridView.java 2006-06-18 18:34:40 UTC (rev 188) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/GridView.java 2006-06-18 22:51:45 UTC (rev 189) @@ -32,9 +32,15 @@ * so that the scaling calculation does not have to be performed * for each paint. */ - protected Image foodImage, subjectImage, selfImage, botImage; + private Image foodImage1, foodImage2, foodImage3, foodImage4; + private Image subjectDownImage, subjectUpImage, subjectLeftImage, subjectRightImage; + private Image selfDownImage, selfUpImage, selfLeftImage, selfRightImage; + private Image botDownImage, botUpImage, botLeftImage, botRightImage; - protected Image scaledFoodImage, scaledSubjectImage, scaledSelfImage, scaledBotImage; + protected Image scaledFoodImage1, scaledFoodImage2, scaledFoodImage3, scaledFoodImage4; + protected Image scaledSubjectDownImage, scaledSubjectUpImage, scaledSubjectLeftImage, scaledSubjectRightImage; + protected Image scaledSelfDownImage, scaledSelfUpImage, scaledSelfLeftImage, scaledSelfRightImage; + protected Image scaledBotDownImage, scaledBotUpImage, scaledBotLeftImage, scaledBotRightImage; /** * Use these for the dimensions when drawing. @@ -67,20 +73,23 @@ // imageUpdate callback is invoked a repaint happens. URL location = null; try { - URLClassLoader imageLoader = URLClassLoader.newInstance(new URL[] { new URL("http", "groups.psych.indiana.edu", "/gee/images/forager/") }); - if (foodImage == null) { - System.out.println("URL is: " + imageLoader.findResource("gem-food.gif")); - foodImage = toolkit.getImage(imageLoader.findResource("gem-food.gif")); - } - if (selfImage == null) { - selfImage = toolkit.getImage(imageLoader.findResource("gem-self.gif")); - } - if (subjectImage == null) { - subjectImage = toolkit.getImage(imageLoader.findResource("gem-red.gif")); - } - if (botImage == null) { - botImage = toolkit.getImage(imageLoader.findResource("gem-gray.gif")); - } + URLClassLoader imageLoader = URLClassLoader.newInstance(new URL[] { new URL("http", "groups.psych.indiana.edu", "/gee/images/forager-v2/") }); + foodImage1 = toolkit.getImage(imageLoader.findResource("grass-1.gif")); + foodImage2 = toolkit.getImage(imageLoader.findResource("grass-2.gif")); + foodImage3 = toolkit.getImage(imageLoader.findResource("grass-3.gif")); + foodImage4 = toolkit.getImage(imageLoader.findResource("grass-4.gif")); + selfDownImage = toolkit.getImage(imageLoader.findResource("you-front.gif")); + selfUpImage = toolkit.getImage(imageLoader.findResource("you-back.gif")); + selfLeftImage = toolkit.getImage(imageLoader.findResource("you-side-left.gif")); + selfRightImage = toolkit.getImage(imageLoader.findResource("you-side-right.gif")); + subjectDownImage = toolkit.getImage(imageLoader.findResource("others-front.gif")); + subjectUpImage = toolkit.getImage(imageLoader.findResource("others-back.gif")); + subjectLeftImage = toolkit.getImage(imageLoader.findResource("others-side-left.gif")); + subjectRightImage = toolkit.getImage(imageLoader.findResource("others-side-right.gif")); + botDownImage = toolkit.getImage(imageLoader.findResource("bot-front.gif")); + botUpImage = toolkit.getImage(imageLoader.findResource("bot-back.gif")); + botLeftImage = toolkit.getImage(imageLoader.findResource("bot-side-left.gif")); + botRightImage = toolkit.getImage(imageLoader.findResource("bot-side-right.gif")); } catch (Exception e) { throw new RuntimeException(e); @@ -88,19 +97,32 @@ } - /** - * Sets dw, and dh, xoffset, and yoffset - * Uses the screenSize as given in the constructor - * along with the current board size. - * Expects the following variables to have been set already: - * 1. the screenSize - * 2. the boardSize - * 3. the images - */ - public void setup(ExperimentRoundParameters parameters) { + private void loadScaledImages() { + int cellWidth = (int) dw; + int cellHeight = (int) dh; + scaledFoodImage1 = foodImage1.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledFoodImage2 = foodImage2.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledFoodImage3 = foodImage3.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledFoodImage4 = foodImage4.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledSubjectDownImage = subjectDownImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledSubjectUpImage = subjectUpImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledSubjectLeftImage = subjectLeftImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledSubjectRightImage = subjectRightImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledSelfDownImage = selfDownImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledSelfUpImage = selfUpImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledSelfLeftImage = selfLeftImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledSelfRightImage = selfRightImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledBotDownImage = botDownImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledBotUpImage = botUpImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledBotLeftImage = botLeftImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + scaledBotRightImage = botRightImage.getScaledInstance(cellWidth, cellHeight, Image.SCALE_FAST); + + } + + private void setScreenSize(Dimension screenSize) { + this.screenSize = screenSize; int availableWidth = (int) screenSize.getWidth(); int availableHeight = (int) screenSize.getHeight(); - setBoardSize(parameters.getBoardSize()); // stretch board to the max dw = (availableWidth / boardSize.getWidth()); @@ -113,16 +135,28 @@ yoffset = (int) Math.floor((availableHeight - (dh * boardSize.getHeight())) / 2); // get scaled instances of the originals - scaledFoodImage = foodImage.getScaledInstance((int) dw, (int) dh, Image.SCALE_FAST); - scaledSubjectImage = subjectImage.getScaledInstance((int) dw, (int) dh, - Image.SCALE_FAST); - scaledSelfImage = selfImage.getScaledInstance((int) dw, (int) dh, Image.SCALE_FAST); - scaledBotImage = botImage.getScaledInstance((int) dw, (int) dh, Image.SCALE_FAST); + loadScaledImages(); // make sure we've got enough room setSize(availableWidth, availableHeight); } + + /** + * Sets dw, and dh, xoffset, and yoffset + * Uses the screenSize as given in the constructor + * along with the current board size. + * Expects the following variables to have been set already: + * 1. the screenSize + * 2. the boardSize + * 3. the images + */ + public void setup(ExperimentRoundParameters parameters) { + setBoardSize(parameters.getBoardSize()); + setScreenSize(screenSize); + + } + private void setBoardSize(Dimension boardSize) { this.boardSize = boardSize; setBackground(Color.BLACK); @@ -131,8 +165,7 @@ } public Dimension getBoardSize() { - // defensive copy to protect for-some-reason public instance vars. - return new Dimension(boardSize); + return boardSize; } @@ -164,23 +197,16 @@ paintCollection(collection, graphics2D, image, null); } - protected void paintCollection(Collection collection, + protected void paintCollection(Collection<Point> collection, Graphics2D graphics2D, Image image, ImageObserver observer) { synchronized (collection) { int width = (int) dw; int height = (int) dh; - for (Iterator iter = collection.iterator(); iter.hasNext(); ) { - Point point = (Point) iter.next(); + for (Point point : collection) { int x = scaleX(point.x); int y = scaleY(point.y); - if (image == null) { - graphics2D.setColor(Color.GREEN); - graphics2D.fillOval(x, y, width, height); - } - else { - graphics2D.drawImage(image, x, y, observer); - } + graphics2D.drawImage(image, x, y, observer); } } } Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/client/DebriefingView.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/client/DebriefingView.java 2006-06-18 18:34:40 UTC (rev 188) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/client/DebriefingView.java 2006-06-18 22:51:45 UTC (rev 189) @@ -76,7 +76,7 @@ } protected void paintFood(Graphics2D g) { - paintCollection(foodPositionsMap.keySet(), g, scaledFoodImage, this); + paintCollection(foodPositionsMap.keySet(), g, scaledFoodImage1, this); } protected void paintSubjects(Graphics2D g) { Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/client/ForagerClient.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/client/ForagerClient.java 2006-06-18 18:34:40 UTC (rev 188) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/client/ForagerClient.java 2006-06-18 22:51:45 UTC (rev 189) @@ -180,6 +180,7 @@ } public void shutdown() { + disconnect(); channel.unregister(this); channel.unregister(messageQueueHandler); } Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/client/ForagerClientGameState.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/client/ForagerClientGameState.java 2006-06-18 18:34:40 UTC (rev 188) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/client/ForagerClientGameState.java 2006-06-18 22:51:45 UTC (rev 189) @@ -27,9 +27,9 @@ public ForagerClientGameState(EventChannel channel) { super(channel); - channel.add(new EventTypeProcessor(RoundStartedEvent.class) { - public void handle(Event event) { - initialize( (RoundStartedEvent) event); + channel.add(new EventTypeProcessor<RoundStartedEvent>(RoundStartedEvent.class) { + public void handle(RoundStartedEvent event) { + initialize(event); } }); } Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/client/SubjectView.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/client/SubjectView.java 2006-06-18 18:34:40 UTC (rev 188) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/client/SubjectView.java 2006-06-18 22:51:45 UTC (rev 189) @@ -40,7 +40,7 @@ private Identifier clientId; // Map<Point, Duration> - private Map foodEaten = new HashMap(); + private Map<Point, Duration> foodEaten = new HashMap<Point, Duration>(); private Visibility subjectVisibility; private Visibility foodVisibility; @@ -84,7 +84,7 @@ // visible radius of the current player, or don't show any food. if (foodVisibility.isFull()) { // render all food - paintCollection(state.getFoodPositions(), graphics2D, scaledFoodImage); + paintCollection(state.getFoodPositions(), graphics2D, scaledFoodImage1); } else if (foodVisibility.isPartial()) { // render food conditionally based on whether or not it lies within @@ -103,10 +103,8 @@ * @param graphics2D */ protected void paintFoodEaten(Graphics2D graphics2D) { - int width = (int) dw; - int height = (int) dh; - int offset = 0; synchronized (foodEaten) { + Image foodImage = null; for (Iterator iter = foodEaten.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = (Map.Entry) iter.next(); @@ -122,32 +120,29 @@ // for a crude animation of food shrinking over time we have an // offset associated with time intervals that we subtract from // the width and height of the food image. - if (elapsedTime < 500L) { - offset = 0; + if (elapsedTime < 400L) { + foodImage = scaledFoodImage1; } - else if (elapsedTime < 1000L) { - offset = 2; + else if (elapsedTime < 800L) { + foodImage = scaledFoodImage2; } - else if (elapsedTime < 1500L) { - offset = 4; + else if (elapsedTime < 1200L) { + foodImage = scaledFoodImage3; } + else if (elapsedTime < 1600L) { + foodImage = scaledFoodImage4; + } // food pellets shrink over time - paintFoodPellet(point, graphics2D, width - offset, height - offset); + paintFoodPellet(point, graphics2D, foodImage); } } } - private void paintFoodPellet(Point point, Graphics2D graphics2D, int width, int height) { + private void paintFoodPellet(Point point, Graphics2D graphics2D, Image image) { int x = scaleX(point.x); int y = scaleY(point.y); - if (scaledFoodImage == null) { - graphics2D.setColor(Color.GREEN); - graphics2D.fillOval(x, y, width, height); - } - else { - graphics2D.drawImage(scaledFoodImage, x, y, width, height, null); - } + graphics2D.drawImage(image, x, y, (int) dw, (int) dh, null); } // FIXME: performance bottleneck, drawImage seems to take a lot of time. @@ -188,15 +183,17 @@ // graphics2D.drawImage(scaledSelfImage, scaleX(selfLocation.x), scaleY(selfLocation.y), null); } + // FIXME: add additional images for up/left/right/etc depending on the + // client direction.. private Image getImageFor(Identifier id) { if ( state.isBot(id) ) { - return scaledBotImage; + return scaledBotDownImage; } else if (id.equals(clientId)) { - return scaledSelfImage; + return scaledSelfDownImage; } else { - return scaledSubjectImage; + return scaledSubjectDownImage; } } } Modified: trunk/gee/src/java/edu/indiana/psych/gee/net/NioDispatcher.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/net/NioDispatcher.java 2006-06-18 18:34:40 UTC (rev 188) +++ trunk/gee/src/java/edu/indiana/psych/gee/net/NioDispatcher.java 2006-06-18 22:51:45 UTC (rev 189) @@ -104,7 +104,6 @@ try { SocketChannel connection = SocketChannel.open(address); // block until we've read the socket identifier from server. - System.err.println("connection: " + connection); Identifier id = readConnectionEvent(connection); worker.process(connection); // XXX: we return an Identifier that's .equals() with the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |