| 933 | } |
| 934 | |
| 935 | Result UpdatePreloader(HPreloader preloader, FPreloaderCompleteCallback complete_callback, PreloaderCompleteCallbackParams* complete_callback_params, uint32_t soft_time_limit) |
| 936 | { |
| 937 | DM_PROFILE("UpdatePreloader"); |
| 938 | |
| 939 | uint64_t start = dmTime::GetMonotonicTime(); |
| 940 | uint32_t empty_runs = 0; |
| 941 | bool close_to_time_limit = soft_time_limit < 1000; |
| 942 | |
| 943 | do |
| 944 | { |
| 945 | Result root_result = preloader->m_Request[0].m_LoadResult; |
| 946 | Result post_create_result = RESULT_OK; |
| 947 | if (preloader->m_PostCreateCallbackIndex < preloader->m_PostCreateCallbacks.Size()) |
| 948 | { |
| 949 | post_create_result = PostCreateUpdateOneItem(preloader); |
| 950 | if (post_create_result != RESULT_PENDING) |
| 951 | { |
| 952 | empty_runs = 0; |
| 953 | if (root_result == RESULT_OK) |
| 954 | { |
| 955 | // Just waiting for the post-create functions to complete |
| 956 | // If main result is RESULT_OK pick up any errors from |
| 957 | // post create function |
| 958 | preloader->m_Request[0].m_LoadResult = post_create_result; |
| 959 | } |
| 960 | continue; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | if (root_result == RESULT_PENDING) |
| 965 | { |
| 966 | if (PreloaderUpdateOneItem(preloader, 0)) |
| 967 | { |
| 968 | empty_runs = 0; |
| 969 | continue; |
| 970 | } |
| 971 | } |
| 972 | else |
| 973 | { |
| 974 | if (!preloader->m_CreateComplete) |
| 975 | { |
| 976 | // Root is resolved - all items has been created, we should now |
| 977 | // call the post-create function (if given) and then post-create |
| 978 | // of all created items |
| 979 | preloader->m_CreateComplete = true; |
| 980 | if (root_result == RESULT_OK && complete_callback) |
| 981 | { |
| 982 | if (!complete_callback(complete_callback_params)) |
| 983 | { |
| 984 | preloader->m_Request[0].m_LoadResult = RESULT_NOT_LOADED; |
| 985 | } |
| 986 | empty_runs = 0; |
| 987 | // We need to continue to do all post create functions |
| 988 | continue; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | if (post_create_result != RESULT_PENDING) |