From f2738dc2e06f172a6db0822d4f94ccdcd6b52da8 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Fri, 30 Jan 2009 15:20:40 -0500 Subject: Fixed AutomaticViewpoint cache issue Previously, heroLoc wasn't a defensive copy of HeroEvent.getLocation(), it was HeroEvent.getLocation(). As of such, the condition that they were inequal always failed. However, a typo in the condition (leaving out the exclamation point) led us to believe it was working fine when in fact, AutomaticViewpoint was recalculating the viewpoint every tick instead of everytime the hero moves. Now it only refreshes when the hero moves or is moving. Also cleared up an ambiguous comment in SpecialEvent's PanViewpoint's JavaDoc. --- .../fourpuzzle/gamestate/mapview/event/SpecialEvent.java | 4 ++-- .../gamestate/mapview/viewpoint/AutomaticViewpoint.java | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 342b65f..43cf626 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java @@ -188,8 +188,8 @@ public class SpecialEvent { /** * Pans the viewpoint the the specified tile location * - * @param x The x coordinate of the tile to pan to - * @param y The y coordinate of the tile to pan to + * @param x The x coordinate of the tile in the top-left corner to pan to + * @param y The y coordinate of the tile in the top-left corner to pan to * @param length How long (in milliseconds) it will take to pan * @param block If true, the game will wait for the pan to complete * before executing any more commands diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/AutomaticViewpoint.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/AutomaticViewpoint.java index fbd7e03..1f8a796 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/AutomaticViewpoint.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/AutomaticViewpoint.java @@ -17,21 +17,22 @@ import java.awt.Point; public class AutomaticViewpoint implements Viewpoint { private Map map; - private Point heroLoc; + private Point heroLoc = new Point(); private Point viewpoint; public AutomaticViewpoint(Map map) { this.map = map; - heroLoc = Game.getHeroEvent().getLocation(); + refresh(); } private void refresh() { int x,y; + HeroEvent hero = Game.getHeroEvent(); - heroLoc = hero.getLocation(); + heroLoc.setLocation(hero.getLocation()); Point endLoc = new Point(hero.getLocation()); if (hero.isMoving()) @@ -76,7 +77,7 @@ public class AutomaticViewpoint implements Viewpoint { public int getX() { - if (Game.getHeroEvent().getLocation().equals(heroLoc)) + if (!Game.getHeroEvent().getLocation().equals(heroLoc) || Game.getHeroEvent().isMoving()) { refresh(); } @@ -86,7 +87,7 @@ public class AutomaticViewpoint implements Viewpoint { public int getY() { - if (!Game.getHeroEvent().getLocation().equals(heroLoc)) + if (!Game.getHeroEvent().getLocation().equals(heroLoc) || Game.getHeroEvent().isMoving()) { refresh(); } -- cgit 1.4.1