diff --git a/Assets/PerfectWorld/Scripts/Task/ATaskTemplMan.cs b/Assets/PerfectWorld/Scripts/Task/ATaskTemplMan.cs index 342d72f17e..1be6115700 100644 --- a/Assets/PerfectWorld/Scripts/Task/ATaskTemplMan.cs +++ b/Assets/PerfectWorld/Scripts/Task/ATaskTemplMan.cs @@ -228,6 +228,85 @@ namespace BrewMonster.Scripts.Task return true; } + public bool LoadTasksFromPackNoAsyn(string szPackPath, bool bLoadDescript) + { + //TaskInterface::WriteLog(0, 0, 2, "LoadPack begin"); + BMLogger.Log("[Dat]- szPackPath: " + szPackPath); + if (!File.Exists(szPackPath)) + { + BMLogger.LogError("[Dat]- File not found: " + szPackPath); + return false; + } + + long readBytes = 0; + FileStream fs = new FileStream(szPackPath, FileMode.Open, FileAccess.Read); + + TASK_PACK_HEADER tph = AAssit.ReadFromBinaryOf(fs, ref readBytes); + + if (tph.magic != TASK_PACK_MAGIC + || tph.version != _task_templ_cur_version) + return false; + + if (tph.item_count == 0) return true; + + uint[] pOffs = new uint[tph.item_count]; + g_ulNewCount++; + + + // fread(pOffs, sizeof(long), tph.item_count, fp); + // read File and prepare offset array before loading tasks + pOffs = AAssit.ReadArrayFromBinary(fs, (int)tph.item_count, ref readBytes); + + Debug.Log((int)tph.item_count); + //BMLogger.Log($" [MH] Task File Lenght: {fs.Length}"); + // for (int i = 2058; i < 2059; i++) //TODO: tph.item_count + Debug.Log($" Starting to load {tph.item_count} task templates..."); + for (int i = 0; i < tph.item_count; i++) + { + // mvoe file pointer to task offset + fs.Seek(pOffs[i], SeekOrigin.Begin); + // BMLogger.Log(" [MH] Loading Task Templ at offset: " + pOffs[i]); + + ATaskTempl pTempl = new ATaskTempl(); + g_ulNewCount++; + + // Debug.Log($"Task Index {i}: Attempting to load task template..."); + if (!pTempl.LoadFromBinFile(fs)) + { + CECTaskInterface.WriteLog(0, (int)pTempl.m_FixedData.m_ID, 0, "Cant Load Task"); + // LOG_DELETE(pTempl); + continue; + } + + AddOneTaskTempl(pTempl); + // TaskInterface::WriteLog(0, pTempl->m_ID, 2, "LoadTask"); + } + + Debug.Log($" Finished loading {m_TaskTemplMap.Count} task templates."); + + // // char log[1024]; + // // sprintf(log, "LoadTask, Count = %d", m_TaskTemplMap.size()); + // // TaskInterface::WriteLog(0, 0, 2, log); + + // //todo: check + // // LOG_DELETE_ARR(pOffs); + fs.Close(); +#if !_TASK_CLIENT + UpdateTimeLimitCheckList(); +#else + SortTasksCanSeekOut(); +#endif + + +#if _ELEMENTCLIENT + // TODO: implement task error logging if needed + // _task_err.Release(); + // _task_err.Init("Configs\\task_err.txt", true); +#endif + + return true; + } + private static List LoadTasksFromPack_Internal(string szPackPath, Action onProgress, CancellationToken token) { long readBytes = 0; diff --git a/Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs b/Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs index 79d2ed6b43..21b9f9f0e8 100644 --- a/Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs +++ b/Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs @@ -437,6 +437,7 @@ namespace BrewMonster.Scripts.Task pTaskMan.TaskLoadedCount > 100) { Debug.Log($" [TaskInterface] Using TaskTest loaded data with {pTaskMan.TaskLoadedCount} tasks."); + LoadingSceneController.Instance.ShowLoadingScene(false); } else { @@ -452,7 +453,14 @@ namespace BrewMonster.Scripts.Task } #else string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data"); - await pTaskMan.LoadTasksFromPack(task_data_path, true); + await pTaskMan.LoadTasksFromPack(task_data_path, true, (x) => + { + UniTask.Void(async () => + { + await UniTask.SwitchToMainThread(); + LoadingSceneController.Instance.UpdateUI(x); + }); + }, _cts.Token); #endif var task_npc_path = Path.Combine(Application.streamingAssetsPath, "data/task_npc.data"); await pTaskMan.LoadNPCInfoFromPack(task_npc_path); diff --git a/Assets/PerfectWorld/Scripts/Task/TaskTest.cs b/Assets/PerfectWorld/Scripts/Task/TaskTest.cs index 5bee5f08ca..b0ebffc15e 100644 --- a/Assets/PerfectWorld/Scripts/Task/TaskTest.cs +++ b/Assets/PerfectWorld/Scripts/Task/TaskTest.cs @@ -129,8 +129,9 @@ namespace BrewMonster.Scripts.Task m_pTaskMan = new ATaskTemplMan(); } + if (_cts == null) _cts = new CancellationTokenSource(); string path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data"); - WasLoadTaskData = await m_pTaskMan.LoadTasksFromPack(path, true,(x)=>{},_cts.Token); + WasLoadTaskData = m_pTaskMan.LoadTasksFromPackNoAsyn(path, true); } [ContextMenu("Test Size")]