Skip to content

Commit 91f76ab

Browse files
committed
change how task manager handles and cancels tasks. now cancellation is handled by the callers who created the task by simply calling Cancel method in the task object. task manager then skip this objects when it's their time to execute
cleanup tile.cs class a little removed map initializationStatus enum ViewLoaded, it's replaced by LoadingView. end of the loading process should be marked by ReadyForUpdates rework LoadMapView method a little bit, created an overload taking latlng. will probably add another one taking mapInformation remove bunch of unused fields from telemetryAndroid fix a bug in pbf source where it didn't check memory cache before coroutine map loads
1 parent a1a78c8 commit 91f76ab

File tree

23 files changed

+1085
-2007
lines changed

23 files changed

+1085
-2007
lines changed

Runtime/Mapbox/BaseModule/Data/DataFetchers/DataFetchingManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class DataFetchingManager : IFileSource
1515
/// <summary>
1616
/// A fetch command in queue is about the get started.
1717
/// </summary>
18-
public Action<FetchInfo> TileInitialized = (t)=> {};
18+
public Action<FetchInfo> FetchInitialized = (t)=> {};
1919

2020
/// <summary>
2121
/// This doesn't mean success or failure, it shows a fetch command fired from queue
@@ -85,11 +85,9 @@ private IEnumerator UpdateTick()
8585
{
8686
_fetchQueue.Dequeue();
8787
_globalActiveRequests.Add(info);
88-
TileInitialized(info);
88+
FetchInitialized(info);
8989
info.Tile.Initialize(
9090
_fileSource,
91-
info.Tile.Id,
92-
info.Tile.TilesetId,
9391
(dataFetchingResult) =>
9492
{
9593
_globalActiveRequests.Remove(info);

Runtime/Mapbox/BaseModule/Data/Platform/Cache/FileCache.cs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,35 +209,38 @@ protected virtual void SaveInfo(InfoWrapper info)
209209
Directory.CreateDirectory(folderPath);
210210
}
211211

212-
_taskManager.AddTask(
213-
new TaskWrapper(info.TextureCacheItem.TileId.GenerateKey(info.TextureCacheItem.TilesetId, "FileCache"))
212+
//we don't track task here anymore as we don't inted to cancel it
213+
//so it's fire and forget task with low priority
214+
var task = new TaskWrapper()
215+
{
216+
TileId = info.TextureCacheItem.TileId,
217+
TilesetId = info.TextureCacheItem.TilesetId,
218+
Action = () =>
214219
{
215-
TileId = info.TextureCacheItem.TileId,
216-
TilesetId = info.TextureCacheItem.TilesetId,
217-
Action = () =>
218-
{
219-
var fullPath = RelativeFilePathToFileInfoExpects(info.Path);
220-
FileStream sourceStream = new FileStream(
221-
RelativeFilePathToFileInfoExpects(info.Path),
222-
FileMode.Create, FileAccess.Write, FileShare.Read,
223-
bufferSize: 4096, useAsync: false);
224-
225-
sourceStream.Write(info.TextureCacheItem.Data, 0, info.TextureCacheItem.Data.Length);
226-
sourceStream.Close();
227-
228-
var finalRelativePath = FullFilePathToRelativePath(fullPath);
229-
info.PostSaveAction(finalRelativePath);
230-
//Debug.Log(string.Format("File saved {0} - {1}", info.TextureCacheItem.TileId, info.Path));
231-
OnFileSaved(info.TextureCacheItem, finalRelativePath);
232-
},
233-
ContinueWith = (t) =>
234-
{
235-
236-
},
220+
var fullPath = RelativeFilePathToFileInfoExpects(info.Path);
221+
FileStream sourceStream = new FileStream(
222+
RelativeFilePathToFileInfoExpects(info.Path),
223+
FileMode.Create, FileAccess.Write, FileShare.Read,
224+
bufferSize: 4096, useAsync: false);
225+
226+
sourceStream.Write(info.TextureCacheItem.Data, 0, info.TextureCacheItem.Data.Length);
227+
sourceStream.Close();
228+
229+
var finalRelativePath = FullFilePathToRelativePath(fullPath);
230+
info.PostSaveAction(finalRelativePath);
231+
//Debug.Log(string.Format("File saved {0} - {1}", info.TextureCacheItem.TileId, info.Path));
232+
OnFileSaved(info.TextureCacheItem, finalRelativePath);
233+
},
234+
ContinueWith = (t) =>
235+
{
236+
237+
},
237238
#if UNITY_EDITOR
238-
Info = "FileCache.SaveInfo"
239+
Info = "FileCache.SaveInfo"
239240
#endif
240-
}, 4);
241+
};
242+
243+
_taskManager.AddTask(task, 4);
241244
}
242245

243246

Runtime/Mapbox/BaseModule/Data/Platform/Cache/MapboxCacheManager.cs

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public interface IMapboxCacheManager
1616
void SaveBlob(MapboxTileData vectorCacheItem, bool forceInsert);
1717
void SaveImage(RasterData textureCacheItem, bool forceInsert);
1818
void GetImageAsync<T>(CanonicalTileId tileId, string tilesetId, bool isTextureNonreadable, Action<T> callback) where T : RasterData, new();
19-
void GetTileInfoAsync<T>(CanonicalTileId tileId, string tilesetid , Action<T> callback, int priority = 1) where T : MapboxTileData, new();
20-
void ReadEtagExpiration<T>(T data, Action callback, int priority = 1) where T : MapboxTileData, new();
19+
TaskWrapper GetTileInfoAsync<T>(CanonicalTileId tileId, string tilesetid , Action<T> callback, int priority = 1) where T : MapboxTileData, new();
20+
TaskWrapper ReadEtagExpiration<T>(T data, Action callback, int priority = 1) where T : MapboxTileData, new();
2121
void UpdateExpiration(CanonicalTileId tileId, string tilesetId, DateTime date);
2222
}
2323

@@ -108,66 +108,69 @@ public void SaveImage(RasterData textureCacheItem, bool forceInsert)
108108
}
109109
}
110110

111-
public void GetTileInfoAsync<T>(CanonicalTileId tileId, string tilesetid, Action<T> callback, int priority = 1) where T : MapboxTileData, new()
111+
public TaskWrapper GetTileInfoAsync<T>(CanonicalTileId tileId, string tilesetid, Action<T> callback, int priority = 1) where T : MapboxTileData, new()
112112
{
113113
if (_sqLiteCache != null)
114114
{
115115
T data = null;
116-
_taskManager.AddTask(
117-
new TaskWrapper(tileId.GenerateKey(tilesetid, "GetTileInfoAsync"))
116+
var task = new TaskWrapper()
117+
{
118+
TileId = tileId,
119+
TilesetId = tilesetid,
120+
Action = () => { data = _sqLiteCache.Get<T>(tilesetid, tileId); },
121+
ContinueWith = (t) =>
118122
{
119-
TileId = tileId,
120-
TilesetId = tilesetid,
121-
Action = () => { data = _sqLiteCache.Get<T>(tilesetid, tileId); },
122-
ContinueWith = (t) =>
123+
if (data == null || data.HasError)
124+
{
125+
callback?.Invoke(null);
126+
}
127+
else
123128
{
124-
if (data == null || data.HasError)
125-
{
126-
callback?.Invoke(null);
127-
}
128-
else
129-
{
130-
callback?.Invoke(data);
131-
}
132-
},
129+
callback?.Invoke(data);
130+
}
131+
},
133132
#if UNITY_EDITOR
134-
Info = "MapboxCacheManager.GetTileInfoAsync"
133+
Info = "MapboxCacheManager.GetTileInfoAsync"
135134
#endif
136-
}, priority);
135+
};
136+
_taskManager.AddTask(task, priority);
137+
return task;
137138
}
138139
else
139140
{
140-
callback?.Invoke(null);
141+
return null;
141142
}
142143
}
143144

144-
public void ReadEtagExpiration<T>(T data, Action callback, int priority = 4) where T : MapboxTileData, new()
145+
public TaskWrapper ReadEtagExpiration<T>(T data, Action callback, int priority = 4) where T : MapboxTileData, new()
145146
{
146-
_taskManager.AddTask(
147-
new TaskWrapper(data.TileId.GenerateKey(data.TilesetId, "ReadEtagExpiration"))
147+
var task = new TaskWrapper()
148+
{
149+
TileId = data.TileId,
150+
TilesetId = data.TilesetId,
151+
Action = () =>
148152
{
149-
TileId = data.TileId,
150-
TilesetId = data.TilesetId,
151-
Action = () =>
153+
_sqLiteCache.ReadEtagAndExpiration<T>(data);
154+
},
155+
ContinueWith = (t) =>
156+
{
157+
if (data.HasError)
152158
{
153-
_sqLiteCache.ReadEtagAndExpiration<T>(data);
154-
},
155-
ContinueWith = (t) =>
159+
callback?.Invoke();
160+
}
161+
else
156162
{
157-
if (data.HasError)
158-
{
159-
callback?.Invoke();
160-
}
161-
else
162-
{
163163

164-
callback?.Invoke();
165-
}
166-
},
164+
callback?.Invoke();
165+
}
166+
},
167167
#if UNITY_EDITOR
168-
Info = "MapboxCacheManager.ReadEtagExpiration"
168+
Info = "MapboxCacheManager.ReadEtagExpiration"
169169
#endif
170-
}, priority);
170+
};
171+
172+
_taskManager.AddTask(task, priority);
173+
return task;
171174
}
172175

173176
public void UpdateExpiration(CanonicalTileId tileId, string tilesetId, DateTime date)
@@ -235,10 +238,10 @@ public void OnDestroy()
235238

236239
public void CancelFetching(CanonicalTileId tileId, string tilesetId)
237240
{
238-
var key = tileId.GenerateKey(tilesetId, "GetTileInfoAsync");
239-
_taskManager.CancelTask(key);
240-
key = tileId.GenerateKey(tilesetId, "ReadEtagExpiration");
241-
_taskManager.CancelTask(key);
241+
// var key = tileId.GenerateKey(tilesetId, "GetTileInfoAsync");
242+
// _taskManager.CancelTask(key);
243+
// key = tileId.GenerateKey(tilesetId, "ReadEtagExpiration");
244+
// _taskManager.CancelTask(key);
242245
}
243246

244247
public static void DeleteAllCache()

Runtime/Mapbox/BaseModule/Data/Platform/Cache/SQLiteCache/SqliteCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void SyncAdd(string tilesetName, CanonicalTileId tileId, byte[] data, str
248248
public virtual void UpdateExpiration(string tilesetName, CanonicalTileId tileId, DateTime expirationDate)
249249
{
250250
_taskManager.AddTask(
251-
new TaskWrapper(tileId.GenerateKey(tilesetName, "SqliteCacheUpdateExpiration"))
251+
new TaskWrapper()
252252
{
253253
OwnerTileId = tileId,
254254
TileId = tileId,
@@ -471,7 +471,7 @@ protected virtual void Add(string tilesetName, CanonicalTileId tileId, byte[] da
471471
}
472472

473473
_taskManager.AddTask(
474-
new TaskWrapper(tileId.GenerateKey(tilesetName, "SqliteCache"))
474+
new TaskWrapper()
475475
{
476476
OwnerTileId = tileId,
477477
TileId = tileId,

Runtime/Mapbox/BaseModule/Data/Tasks/MeshGenTaskWrapper.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ public class MeshGenTaskWrapper : TaskWrapper
77
{
88
public Func<MeshGenTaskWrapperResult> MeshGen;
99
public Action<MeshGenTaskWrapperResult> ContinueMeshWith;
10-
public MeshGenTaskWrapper(int id) : base(id)
11-
{
12-
}
1310
}
1411

1512
public class MeshGenTaskWrapperResult : TaskResult

0 commit comments

Comments
 (0)