* Fix #361

* Clean up debugging changes.

* Fix one compile error.
This commit is contained in:
Lucas Girouard-Stranks
2017-04-09 22:15:36 +10:00
committed by Dylan Wilson
parent cbd4cabe68
commit 435d973a20
3 changed files with 41 additions and 33 deletions
@@ -492,3 +492,8 @@
/processorParam:TextureFormat=Color
/build:TiledMaps/voxelTiles_sheet.png
#begin TiledMaps/level08.tmx
/importer:TiledMapImporter
/processor:TiledMapProcessor
/build:TiledMaps/level08.tmx
@@ -14,7 +14,6 @@ namespace Demo.Features.Demos
{
public class TiledMapsDemo : DemoBase
{
private FramesPerSecondCounter _fpsCounter;
private BitmapFont _bitmapFont;
private Camera2D _camera;
private SpriteBatch _spriteBatch;
@@ -38,8 +37,6 @@ namespace Demo.Features.Demos
Window.AllowUserResizing = true;
_fpsCounter = new FramesPerSecondCounter();
base.Initialize();
}
@@ -49,7 +46,7 @@ namespace Demo.Features.Demos
_bitmapFont = Content.Load<BitmapFont>("Fonts/montserrat-32");
_availableMaps =
new Queue<string>(new[] { "level01", "level02", "level03", "level04", "level05", "level06", "level07" });
new Queue<string>(new[] { "level01", "level02", "level03", "level04", "level05", "level06", "level07", "level08" });
_map = LoadNextMap();
_camera.LookAt(new Vector2(_map.WidthInPixels, _map.HeightInPixels) * 0.5f);
@@ -80,7 +77,6 @@ namespace Demo.Features.Demos
{
var deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
var keyboardState = Keyboard.GetState();
var mouseState = Mouse.GetState();
_mapRenderer.Update(_map, gameTime);
@@ -139,8 +135,6 @@ namespace Demo.Features.Demos
_previousKeyboardState = keyboardState;
_fpsCounter.Update(gameTime);
base.Update(gameTime);
}
@@ -176,8 +170,6 @@ namespace Demo.Features.Demos
DrawText();
_fpsCounter.Draw(gameTime);
base.Draw(gameTime);
}
@@ -186,19 +178,13 @@ namespace Demo.Features.Demos
var textColor = Color.Black;
_spriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend);
var baseTextPosition = new Point2(5, 0);
// textPosition = base position (point) + offset (vector2)
var baseTextPosition = new Point2(5, _bitmapFont.LineHeight);
var textPosition = baseTextPosition + new Vector2(0, _bitmapFont.LineHeight * 0);
_spriteBatch.DrawString(_bitmapFont,
$"Map: {_map.Name}; {_map.TileLayers.Count} tile layer(s) @ {_map.Width}x{_map.Height} tiles, {_map.ImageLayers.Count} image layer(s)",
textPosition, textColor);
textPosition = baseTextPosition + new Vector2(0, _bitmapFont.LineHeight * 1);
// we can safely get the metrics without worrying about spritebatch interfering because spritebatch submits on End()
_spriteBatch.DrawString(_bitmapFont,
$"FPS: {_fpsCounter.FramesPerSecond:0}, Draw Calls: {GraphicsDevice.Metrics.DrawCount}, Texture TotalCount: {GraphicsDevice.Metrics.TextureCount}, Triangle TotalCount: {GraphicsDevice.Metrics.PrimitiveCount}",
textPosition, textColor);
textPosition = baseTextPosition + new Vector2(0, _bitmapFont.LineHeight * 2);
_spriteBatch.DrawString(_bitmapFont, $"Camera Position: (x={_camera.Position.X}, y={_camera.Position.Y})",
textPosition, textColor);
@@ -27,14 +27,14 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
return map;
}
private static TiledMapContent DeserializeTiledMapContent(string filePath)
private static TiledMapContent DeserializeTiledMapContent(string mapFilePath)
{
using (var reader = new StreamReader(filePath))
using (var reader = new StreamReader(mapFilePath))
{
var mapSerializer = new XmlSerializer(typeof(TiledMapContent));
var map = (TiledMapContent)mapSerializer.Deserialize(reader);
map.FilePath = filePath;
map.FilePath = mapFilePath;
var tilesetSerializer = new XmlSerializer(typeof(TiledMapTilesetContent));
@@ -44,26 +44,43 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
if (string.IsNullOrWhiteSpace(tileset.Source))
continue;
var directoryName = Path.GetDirectoryName(filePath);
var tilesetLocation = tileset.Source.Replace('/', Path.DirectorySeparatorChar);
Debug.Assert(directoryName != null, "directoryName != null");
var tilesetFilePath = Path.Combine(directoryName, tilesetLocation);
ContentLogger.Log($"Importing tileset '{tilesetFilePath}'");
using (var file = new FileStream(tilesetFilePath, FileMode.Open))
{
map.Tilesets[i] = (TiledMapTilesetContent)tilesetSerializer.Deserialize(file);
}
ContentLogger.Log($"Imported tileset '{tilesetFilePath}'");
var tilesetFilePath = GetTilesetFilePath(mapFilePath, tileset);
map.Tilesets[i] = ImportTileset(tilesetFilePath, tilesetSerializer, tileset);
}
map.Name = filePath;
map.Name = mapFilePath;
return map;
}
}
private static string GetTilesetFilePath(string mapFilePath, TiledMapTilesetContent tileset)
{
var directoryName = Path.GetDirectoryName(mapFilePath);
Debug.Assert(directoryName != null, "directoryName != null");
var tilesetLocation = tileset.Source.Replace('/', Path.DirectorySeparatorChar);
var tilesetFilePath = Path.Combine(directoryName, tilesetLocation);
return tilesetFilePath;
}
private static TiledMapTilesetContent ImportTileset(string tilesetFilePath, XmlSerializer tilesetSerializer, TiledMapTilesetContent tileset)
{
TiledMapTilesetContent result;
ContentLogger.Log($"Importing tileset '{tilesetFilePath}'");
using (var file = new FileStream(tilesetFilePath, FileMode.Open))
{
var importedTileset = (TiledMapTilesetContent)tilesetSerializer.Deserialize(file);
importedTileset.FirstGlobalIdentifier = tileset.FirstGlobalIdentifier;
result = importedTileset;
}
ContentLogger.Log($"Imported tileset '{tilesetFilePath}'");
return result;
}
}
}