OSDN Git Service

!A - Adds Javadocs for new Tiled objects, map, loader and renderer
authorsiondream <david.saltares@gmail.com>
Wed, 13 Feb 2013 08:05:17 +0000 (08:05 +0000)
committersiondream <david.saltares@gmail.com>
Wed, 13 Feb 2013 08:05:17 +0000 (08:05 +0000)
gdx/src/com/badlogic/gdx/maps/loaders/TmxMapLoader.java
gdx/src/com/badlogic/gdx/maps/tiled/TiledMap.java
gdx/src/com/badlogic/gdx/maps/tiled/TiledMapRenderer.java
gdx/src/com/badlogic/gdx/maps/tiled/TiledMapTile.java
gdx/src/com/badlogic/gdx/maps/tiled/TiledMapTileLayer.java
gdx/src/com/badlogic/gdx/maps/tiled/TiledMapTileSet.java
gdx/src/com/badlogic/gdx/maps/tiled/TiledMapTileSets.java
gdx/src/com/badlogic/gdx/maps/tiled/tiles/StaticTiledMapTile.java

index 37e992d..f0a5166 100644 (file)
@@ -34,6 +34,9 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
 import com.badlogic.gdx.utils.XmlReader;
 import com.badlogic.gdx.utils.XmlReader.Element;
 
+/**
+ * @brief synchronous loader for TMX maps created with the Tiled tool
+ */
 public class TmxMapLoader extends SynchronousAssetLoader<TiledMap, TmxMapLoader.Parameters> {
 
        public static class Parameters extends AssetLoaderParameters<TiledMap> {
@@ -49,10 +52,23 @@ public class TmxMapLoader extends SynchronousAssetLoader<TiledMap, TmxMapLoader.
        private FileHandle tmx;
        private XmlReader xml;
        
+       /**
+        * Creates loader 
+        *  
+        * @param resolver
+        */
        public TmxMapLoader(FileHandleResolver resolver) {
                super(resolver);
        }
 
+       /**
+        * Loads a .tmx file
+        * 
+        * @param assetManager
+        * @param fileName
+        * @param parameter not used for now
+        * @return loaded TiledMap instance
+        */
        @Override
        public TiledMap load(AssetManager assetManager, String fileName, Parameters parameter) {
                this.assetManager = assetManager;
@@ -86,6 +102,13 @@ public class TmxMapLoader extends SynchronousAssetLoader<TiledMap, TmxMapLoader.
                return null;
        }
 
+       /**
+        * Retrieves TiledMap resource dependencies
+        * 
+        * @param fileName
+        * @param parameter not used for now
+        * @return dependencies for the given .tmx file
+        */
        @Override
        public Array<AssetDescriptor> getDependencies(String fileName, Parameters parameter) {
                Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>();
index 44a2811..103ef0d 100644 (file)
@@ -2,14 +2,25 @@ package com.badlogic.gdx.maps.tiled;
 
 import com.badlogic.gdx.maps.Map;
 
+/**
+ * @brief Represents a Tiled created map, adds the concept of tiles and tilesets
+ * 
+ * @see Map
+ */
 public class TiledMap extends Map {
        
        private TiledMapTileSets tilesets;
        
+       /**
+        * @return collection of tilesets for this map
+        */
        public TiledMapTileSets getTileSets() {
                return tilesets;
        }
        
+       /**
+        * Creates empty TiledMap
+        */
        public TiledMap() {
                tilesets = new TiledMapTileSets();
        }
index a0a04f7..d42ea76 100644 (file)
@@ -10,6 +10,11 @@ import com.badlogic.gdx.maps.MapRenderer;
 import com.badlogic.gdx.math.Matrix4;
 import com.badlogic.gdx.utils.Disposable;
 
+/**
+ * @brief Logic for rendering TiledMap objects
+ * 
+ * Includes several optimisations such as SpriteCache usage, fustrum culling etc.
+ */
 public class TiledMapRenderer implements MapRenderer, Disposable {
 
        private Map map;
@@ -20,34 +25,63 @@ public class TiledMapRenderer implements MapRenderer, Disposable {
        
        private boolean ownsSpriteBatch = false;
        
+       /**
+        * @return map currently being used for rendering
+        */
        public Map getMap() {
                return map;
        }
        
+       /**
+        * @return batch used for rendering
+        */
        public SpriteBatch getSpriteBatch() {
                return spriteBatch;
        }
        
+       /**
+        * @return world units per pixel used for rendering
+        */
        public float getUnitScale() {
                return unitScale;
        }
        
+       /**
+        * Creates a renderer from a map. Will use own spritebatch and world units of 1.0 pixels
+        * 
+        * @param map will use this map for rendering 
+        */
        public TiledMapRenderer(TiledMap map) {
                this(map, new SpriteBatch());
                ownsSpriteBatch = true;
        }
        
+       /**
+        * Creates a renderer from a map using the given world units. Will use a batch from its own.
+        * 
+        * @param map will use this map for rendering
+        * @param unitScale world units per pixel
+        */
        public TiledMapRenderer(TiledMap map, float unitScale) {
                this(map, new SpriteBatch(), unitScale);
                ownsSpriteBatch = true;
        }
        
+       /**
+        * @param map will use this map for rendering
+        * @param spriteBatch batch that will be used for rendering
+        */
        public TiledMapRenderer(TiledMap map, SpriteBatch spriteBatch) {
                this.map = map;
                this.spriteBatch = spriteBatch;
                this.ownsSpriteBatch = false;
        }
        
+       /**
+        * @param map will use this map for rendering
+        * @param spriteBatch batch that will be used for rendering
+        * @param unitScale world units per pixel
+        */
        public TiledMapRenderer(TiledMap map, SpriteBatch spriteBatch, float unitScale) {
                this.map = map;
                this.spriteBatch = spriteBatch;
@@ -55,6 +89,9 @@ public class TiledMapRenderer implements MapRenderer, Disposable {
                this.ownsSpriteBatch = false;
        }
 
+       /**
+        * @param projection projection matrix that will be used for rendering the map
+        */
        @Override
        public void setProjectionMatrix (Matrix4 projection) {
                spriteBatch.setProjectionMatrix(projection);
@@ -105,8 +142,13 @@ public class TiledMapRenderer implements MapRenderer, Disposable {
                }
        }
        
-       /* (non-Javadoc)
-        * @see com.badlogic.gdx.maps.MapRenderer2#render(float, float, float, float, int[])
+       /**
+        * Renders all the layers using the projection matrix and the given bounds for fustrum culling
+        * 
+        * @param viewboundsX
+        * @param viewboundsY
+        * @param viewboundsWidth
+        * @param viewboundsHeight
         */
        @Override
        public void render (float viewboundsX, float viewboundsY, float viewboundsWidth, float viewboundsHeight) {
@@ -116,8 +158,14 @@ public class TiledMapRenderer implements MapRenderer, Disposable {
                }
        }
        
-       /* (non-Javadoc)
-        * @see com.badlogic.gdx.maps.MapRenderer2#render(float, float, float, float, int[])
+       /**
+        * Renders the given layers using the projection matrix and the given bounds for fustrum culling
+        * 
+        * @param viewboundsX
+        * @param viewboundsY
+        * @param viewboundsWidth
+        * @param viewboundsHeight
+        * @param layers
         */
        @Override
        public void render (float viewboundsX, float viewboundsY, float viewboundsWidth, float viewboundsHeight, int[] layers) {
index c0e06b4..ff1e50c 100644 (file)
@@ -3,10 +3,20 @@ package com.badlogic.gdx.maps.tiled;
 import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.maps.MapProperties;
 
+/**
+ * @brief Generalises the concept of tile in a TiledMap
+ *
+ */
 public interface TiledMapTile {
 
+       /**
+        * @return texture region used to render the tile
+        */
        public TextureRegion getTextureRegion();
 
+       /**
+        * @return tile's properties set
+        */
        public MapProperties getProperties();
        
 }
index c969ce7..6325411 100644 (file)
@@ -2,6 +2,9 @@ package com.badlogic.gdx.maps.tiled;
 
 import com.badlogic.gdx.maps.MapLayer;
 
+/**
+ * @brief Layer for a TiledMap 
+ */
 public class TiledMapTileLayer extends MapLayer {
 
        private int width;
@@ -12,22 +15,42 @@ public class TiledMapTileLayer extends MapLayer {
        
        private Cell[][] cells;
        
+       /**
+        * @return layer's witdth in tiles
+        */
        public int getWidth() {
                return width;
        }
        
+       /**
+        * @return layer's height in tiles
+        */
        public int getHeight() {
                return height;
        }
        
+       /**
+        * @return tiles' width in pixels
+        */
        public float getTileWidth() {
                return tileWidth;
        }
        
+       /**
+        * @return tiles' height in pixels
+        */
        public float getTileHeight() {
                return tileHeight;
        }
        
+       /**
+        * Creates TiledMap layer
+        * 
+        * @param width layer width in tiles
+        * @param height layer height in tiles
+        * @param tileWidth tile width in pixels
+        * @param tileHeight tile height in pixels 
+        */
        public TiledMapTileLayer(int width, int height, int tileWidth, int tileHeight) {
                super();
                this.width = width;
@@ -42,6 +65,11 @@ public class TiledMapTileLayer extends MapLayer {
                }
        }
        
+       /**
+        * @param x
+        * @param y 
+        * @return cell at (x, y)
+        */
        public Cell getCell(int x, int y) {
                return cells[x][y];
        }
@@ -57,6 +85,9 @@ public class TiledMapTileLayer extends MapLayer {
                cells[x][y].setTile(tile);
        }
        
+       /**
+        * @brief represents a slot in a TiledLayer: TiledMapTile, flip and rotation properties.
+        */
        public class Cell {
                
                private TiledMapTile tile;
index e1902ab..3affe23 100644 (file)
@@ -3,6 +3,9 @@ package com.badlogic.gdx.maps.tiled;
 import com.badlogic.gdx.maps.MapProperties;
 import com.badlogic.gdx.utils.IntMap;
 
+/**
+ * @brief Set of TiledMapTile instances used to compose a TiledMapLayer
+ */
 public class TiledMapTileSet {
        
        private String name;
@@ -11,31 +14,56 @@ public class TiledMapTileSet {
 
        private MapProperties properties;
 
+       /**
+        * @return tileset's name
+        */
        public String getName() {
                return name;
        }
        
+       /**
+        * @param name new name for the tileset
+        */
        public void setName(String name) {
                this.name = name;
        }
        
+       /**
+        * @return tileset's properties set
+        */
        public MapProperties getProperties() {
                return properties;
        }
        
+       /**
+        * Creates empty tileset
+        */
        public TiledMapTileSet() {
                tiles = new IntMap<TiledMapTile>();
                properties = new MapProperties();
        }
        
+       /**
+        * @param id
+        * @return tile matching id, null if it doesn't exist
+        */
        public TiledMapTile getTile(int id) {
                return tiles.get(id);
        }
        
+       /**
+        * Adds or replaces tile with that id
+        * 
+        * @param id
+        * @param tile
+        */
        public void putTile(int id, TiledMapTile tile) {
                tiles.put(id, tile);
        }
        
+       /**
+        * @param id tile's id to be removed
+        */
        public void removeTile(int id) {
                tiles.remove(id);
        }
index d3ebd12..82b8fa5 100644 (file)
@@ -4,18 +4,32 @@ import java.util.Iterator;
 
 import com.badlogic.gdx.utils.Array;
 
+/**
+ * @brief Collection of TiledMapTileSet
+ */
 public class TiledMapTileSets implements Iterable<TiledMapTileSet> {
        
        private Array<TiledMapTileSet> tilesets;
        
+       /**
+        * Creates empty collection of tilesets
+        */
        public TiledMapTileSets() {
                tilesets = new Array<TiledMapTileSet>();
        }
        
+       /**
+        * @param index
+        * @return tileset at index
+        */
        public TiledMapTileSet getTileSet(int index) {
                return tilesets.get(index);
        }
        
+       /**
+        * @param name
+        * @return tileset with matching name, null if it doesn't exist
+        */
        public TiledMapTileSet getTileSet(String name) {
                for (TiledMapTileSet tileset : tilesets) {
                        if (name.equals(tileset.getName())) {
@@ -25,18 +39,33 @@ public class TiledMapTileSets implements Iterable<TiledMapTileSet> {
                return null;
        }
        
+       /**
+        * @param tileset set to be added to the collection
+        */
        public void addTileSet(TiledMapTileSet tileset) {
                tilesets.add(tileset);
        }
        
+       /**
+        * Removes tileset at index
+        * 
+        * @param index
+        */
        public void removeTileSet(int index) {
                tilesets.removeIndex(index);
        }
        
+       /**
+        * @param tileset set to be removed
+        */
        public void removeTileSet(TiledMapTileSet tileset) {
                tilesets.removeValue(tileset, true);
        }
        
+       /**
+        * @param id
+        * @return tile with matching id, null if it doesn't exist
+        */
        public TiledMapTile getTile(int id) {
                for (TiledMapTileSet tileset : tilesets) {
                        TiledMapTile tile = tileset.getTile(id);
@@ -47,6 +76,9 @@ public class TiledMapTileSets implements Iterable<TiledMapTileSet> {
                return null;
        }
        
+       /**
+        * @return iterator to tilesets
+        */
        @Override
        public Iterator<TiledMapTileSet> iterator() {
                return tilesets.iterator();
index c3fb28e..9486296 100644 (file)
@@ -4,26 +4,45 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.maps.MapProperties;
 import com.badlogic.gdx.maps.tiled.TiledMapTile;
 
+/**
+ * @brief Represents a non changing TiledMapTile (can be cached)
+ */
 public class StaticTiledMapTile implements TiledMapTile {
 
        private MapProperties properties;
        
        private TextureRegion textureRegion;    
 
+       /**
+        * @return tile's properties set
+        */
        @Override
        public MapProperties getProperties() {
                return properties;
        }
-       
+
+       /**
+        * @return texture region used to render the tile
+        */
        @Override
        public TextureRegion getTextureRegion() {
                return textureRegion;
        }
        
+       /**
+        * Creates a static tile with the given region
+        * 
+        * @param textureRegion
+        */
        public StaticTiledMapTile(TextureRegion textureRegion) {
                this.textureRegion = textureRegion;
        }
        
+       /**
+        * Copy constructor
+        * 
+        * @param copy
+        */
        public StaticTiledMapTile(StaticTiledMapTile copy) {
                this.properties.putAll(copy.properties);
                this.textureRegion = copy.textureRegion;