maptile retrieval via SL's external Map API can work.

This commit is contained in:
alexiscatnip
2021-08-14 18:03:36 +08:00
parent d1af30e8ac
commit 9e953b876b
2 changed files with 30 additions and 18 deletions
+14 -2
View File
@@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace Raindrop.Map
{
/// <summary>
/// API to retrieve, delete, modify MapTiles in the scene
/// API to retrieve, delete, modify, create MapTiles in the scene
/// </summary>
public class MapDataManager
{
@@ -34,7 +34,7 @@ namespace Raindrop.Map
}
/// <summary>
/// gets a maptile
/// gets a maptile, if it is present
/// </summary>
/// <param name="handle">the region handle of the tile to get ; gridCoords * 256 and pack X&Y together.</param>
/// <returns> Tile </returns>
@@ -52,6 +52,18 @@ namespace Raindrop.Map
return tile;
}
}
/// <summary>
/// creates a blank maptile at a grid handle.
/// </summary>
/// <param name="handle">the region handle of the tile to get ; gridCoords * 256 and pack X&Y together.</param>
/// <returns> Tile </returns>
public MapTile setEmptyTile(ulong handle)
{
MapTile tile = pool.acquireTile();
sceneTiles.Add(handle, tile);
return tile;
}
/// <summary>
/// Returns a Region to the pool. -- EG not visible anymore
+16 -16
View File
@@ -81,9 +81,9 @@ namespace Raindrop.Map
//}
//catch (Exception)
//{
// uint x, y;
// Utils.LongToUInts(handle, out x, out y);
// throw new Exception("no tile found at " + x + " " + y);
uint x, y;
Utils.LongToUInts(handle, out x, out y);
Debug.LogError("no tile found at " + x + " " + y);
//}
return res;
}
@@ -135,11 +135,11 @@ namespace Raindrop.Map
Debug.Log("1");
//decode http response data into texture2d
//MapTile tex = mapData.getTile();
MapTile tex = GetMapTile(handle,1 ); //Tile is a empty tile right now -- we write to it soon.
MapTile tex = mapDataMgr.setEmptyTile(handle); //Tile is a empty tile right now -- we write to it soon.
Debug.Log("2");
//run jpeg decoding on the main thread, for now.
mainThreadInstance.Enqueue(TestAsync(tex, responseData));
mainThreadInstance.Enqueue(DecodeDataToTexAsync(tex, responseData));
Debug.Log("3");
//set the tile into tile manager
@@ -166,20 +166,20 @@ namespace Raindrop.Map
}
}
private IEnumerator TestAsync(MapTile tex, byte[] responseData)
private IEnumerator DecodeDataToTexAsync(MapTile tex, byte[] responseData)
{
//try
//{
// bool success = tex.texture.LoadImage(responseData);
try
{
Texture2D _tex = tex.getTex();
bool success = _tex.LoadImage(responseData);
//}
//catch (Exception w)
//{
// Debug.Log("decode the texture failed : " + w.Message);
//}
//Debug.Log("completed mainthread async texture Decode.");
}
catch (Exception w)
{
Debug.Log("decode the texture failed : " + w.Message);
}
Debug.Log("completed mainthread async texture Decode.");
Debug.Log("5");
yield return null;
}