From 528e32b22eeab5d1c7f23e7de69335a9af8d2d60 Mon Sep 17 00:00:00 2001 From: Walter Korman Date: Wed, 29 Aug 2001 20:07:54 +0000 Subject: [PATCH] Removed now-unnecessary scene view model accessors and simplified set-up and precalculating of view model data. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@320 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../miso/client/IsoSceneViewModel.java | 122 +++++------------- 1 file changed, 32 insertions(+), 90 deletions(-) diff --git a/src/java/com/threerings/miso/client/IsoSceneViewModel.java b/src/java/com/threerings/miso/client/IsoSceneViewModel.java index f404575ae..742def75a 100644 --- a/src/java/com/threerings/miso/client/IsoSceneViewModel.java +++ b/src/java/com/threerings/miso/client/IsoSceneViewModel.java @@ -1,5 +1,5 @@ // -// $Id: IsoSceneViewModel.java,v 1.11 2001/08/29 19:50:46 shaper Exp $ +// $Id: IsoSceneViewModel.java,v 1.12 2001/08/29 20:07:54 shaper Exp $ package com.threerings.miso.scene; @@ -86,24 +86,20 @@ public class IsoSceneViewModel scenehei = config.getValue(SCENE_HEIGHT_KEY, DEF_SCENE_HEIGHT); // get the tile dimensions - int twid = config.getValue(TILE_WIDTH_KEY, DEF_TILE_WIDTH); - int thei = config.getValue(TILE_HEIGHT_KEY, DEF_TILE_HEIGHT); - - // set tile dimensions and pre-calculate related member data - // based on now-known tile and scene dimensions - setTileDimensions(twid, thei); + tilewid = config.getValue(TILE_WIDTH_KEY, DEF_TILE_WIDTH); + tilehei = config.getValue(TILE_HEIGHT_KEY, DEF_TILE_HEIGHT); // set the fine coordinate granularity - setFineGranularity(config.getValue(FINE_GRAN_KEY, DEF_FINE_GRAN)); + finegran = config.getValue(FINE_GRAN_KEY, DEF_FINE_GRAN); // set the desired scene view bounds int svwid = config.getValue(SCENE_VWIDTH_KEY, DEF_SCENE_VWIDTH); int svhei = config.getValue(SCENE_VHEIGHT_KEY, DEF_SCENE_VHEIGHT); - setBounds(svwid * twid, svhei * thei); + bounds = new Dimension(svwid * tilewid, svhei * tilehei); // set the scene display origin int offy = config.getValue(SCENE_OFFSET_Y_KEY, DEF_OFFSET_Y); - setOrigin(bounds.width / 2, offy * thei); + origin = new Point((bounds.width / 2), (offy * tilehei)); // set our various flags showCoords = config.getValue(SHOW_COORDS_KEY, DEF_SHOW_COORDS); @@ -111,18 +107,6 @@ public class IsoSceneViewModel showPaths = config.getValue(SHOW_PATHS_KEY, DEF_SHOW_PATHS); } - /** - * Set the number of fine coordinates within a tile. The - * granularity determines the number of coordinates on both the x- - * and y-axis. - * - * @param gran the number of fine coordinates on each axis. - */ - public void setFineGranularity (int gran) - { - finegran = gran; - } - /** * Return whether locations in the scene are currently drawn. */ @@ -170,77 +154,14 @@ public class IsoSceneViewModel } /** - * Set the dimensions of the tiles that comprise the base layer of - * the isometric view and therefore drive the view geometry as a - * whole. - * - * @param width the tile width in pixels. - * @param height the tile height in pixels. - */ - public void setTileDimensions (int width, int height) - { - // save the dimensions - tilewid = width; - tilehei = height; - - // halve the dimensions - tilehwid = width / 2; - tilehhei = height / 2; - - // calculate the length of a tile edge in pixels - tilelen = (float) Math.sqrt( - (tilehwid * tilehwid) + (tilehhei * tilehhei)); - - // calculate the number of tile rows to render - tilerows = (scenewid * scenehei) - 1; - - // calculate the slope of the x- and y-axis lines - slopeX = (float)tilehei / (float)tilewid; - slopeY = -slopeX; - } - - /** - * Set the origin position at which the isometric view is - * displayed in screen pixel coordinates. - * - * @param x the x-position in pixels. - * @param y the y-position in pixels. - */ - public void setOrigin (int x, int y) - { - // save the requested origin - origin = new Point(x, y); - } - - /** - * Set the desired bounds for the view. The actual resulting - * bounds will be based on the number of whole tiles that fit in - * the requested bounds vertically and horizontally. For the - * bounds to be calculated correctly, therefore, the desired tile - * dimensions should have been previously set via - * setTileDimensions(). - * - * @param width the bounds width in pixels. - * @param height the bounds height in pixels. - */ - public void setBounds (int width, int height) - { - // determine the actual bounds based on the number of whole - // tiles that fit in the requested bounds - int bwid = (width / tilewid) * tilewid; - int bhei = (height / tilehei) * tilehei; - - // save our calculated boundaries in pixel coordinates - bounds = new Dimension(bwid, bhei); - } - - /** - * Pre-calculate various values that are commonly used in working - * with an isometric view. Includes x-axis line values for use in - * converting coordinates, and fine coordinate dimensions. + * Pre-calculate various member data that are commonly used in + * working with an isometric view. */ public void precalculate () { + // pre-calculate tile-related data + precalculateTiles(); + // calculate scene-based x-axis line for conversion from // screen to tile coordinates @@ -274,6 +195,27 @@ public class IsoSceneViewModel finehhei = (int)((float)tilehhei / (float)finegran); } + /** + * Pre-calculate various tile-related member data. + */ + protected void precalculateTiles () + { + // halve the dimensions + tilehwid = (tilewid / 2); + tilehhei = (tilehei / 2); + + // calculate the length of a tile edge in pixels + tilelen = (float) Math.sqrt( + (tilehwid * tilehwid) + (tilehhei * tilehhei)); + + // calculate the number of tile rows to render + tilerows = (scenewid * scenehei) - 1; + + // calculate the slope of the x- and y-axis lines + slopeX = (float)tilehei / (float)tilewid; + slopeY = -slopeX; + } + /** The config key for tile width in pixels. */ protected static final String TILE_WIDTH_KEY = MisoUtil.CONFIG_KEY + ".tile_width";