{"action":"created","issue":{"url":"https://api.github.com/repos/libgdx/libgdx/issues/2875","labels_url":"https://api.github.com/repos/libgdx/libgdx/issues/2875/labels{/name}","comments_url":"https://api.github.com/repos/libgdx/libgdx/issues/2875/comments","events_url":"https://api.github.com/repos/libgdx/libgdx/issues/2875/events","html_url":"https://github.com/libgdx/libgdx/pull/2875","id":58518661,"number":2875,"title":"Include dependencies count when reporting asset manager progress.","user":{"login":"lnr0626","id":704837,"avatar_url":"https://avatars.githubusercontent.com/u/704837?v=3","gravatar_id":"","url":"https://api.github.com/users/lnr0626","html_url":"https://github.com/lnr0626","followers_url":"https://api.github.com/users/lnr0626/followers","following_url":"https://api.github.com/users/lnr0626/following{/other_user}","gists_url":"https://api.github.com/users/lnr0626/gists{/gist_id}","starred_url":"https://api.github.com/users/lnr0626/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lnr0626/subscriptions","organizations_url":"https://api.github.com/users/lnr0626/orgs","repos_url":"https://api.github.com/users/lnr0626/repos","events_url":"https://api.github.com/users/lnr0626/events{/privacy}","received_events_url":"https://api.github.com/users/lnr0626/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-22T21:09:11Z","updated_at":"2015-02-23T00:22:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/libgdx/libgdx/pulls/2875","html_url":"https://github.com/libgdx/libgdx/pull/2875","diff_url":"https://github.com/libgdx/libgdx/pull/2875.diff","patch_url":"https://github.com/libgdx/libgdx/pull/2875.patch"},"body":"This makes it so that when an asset has dependencies, the getProgress() call reflects the actual process for loading the assets. \r\n\r\nI'm not sure if it was created this way intentionally, but in my mind this gives a more accurate indication of the load progress than how it currently is. This can however make the percent completion go backwards at times (which I guess could be why it is the way that it currently is...). If this is an issue for including this change, I'll look into fixing it."},"comment":{"url":"https://api.github.com/repos/libgdx/libgdx/issues/comments/75474838","html_url":"https://github.com/libgdx/libgdx/pull/2875#issuecomment-75474838","issue_url":"https://api.github.com/repos/libgdx/libgdx/issues/2875","id":75474838,"user":{"login":"lnr0626","id":704837,"avatar_url":"https://avatars.githubusercontent.com/u/704837?v=3","gravatar_id":"","url":"https://api.github.com/users/lnr0626","html_url":"https://github.com/lnr0626","followers_url":"https://api.github.com/users/lnr0626/followers","following_url":"https://api.github.com/users/lnr0626/following{/other_user}","gists_url":"https://api.github.com/users/lnr0626/gists{/gist_id}","starred_url":"https://api.github.com/users/lnr0626/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lnr0626/subscriptions","organizations_url":"https://api.github.com/users/lnr0626/orgs","repos_url":"https://api.github.com/users/lnr0626/repos","events_url":"https://api.github.com/users/lnr0626/events{/privacy}","received_events_url":"https://api.github.com/users/lnr0626/received_events","type":"User","site_admin":false},"created_at":"2015-02-23T00:22:05Z","updated_at":"2015-02-23T00:22:05Z","body":"```\r\nint tasksLength = tasks.size();\r\nfloat completedProgress = loaded / (float) toLoad;\r\n```\r\n`completedProgress` is the percent of requested assets which have been fully loaded - it's what is currently being returned.\r\n\r\nThe next bit is the estimation for the progress of the asset which is currently being loaded. If the length of the stack named `tasks` is greater than 1, it means that the dependencies for this task are currently being loaded (or at least that was what I was able to determine). If that's the case, then the progress is estimated as .9 / the number of tasks (which is roughly the number of dependencies to load + 1). \r\n\r\nIf the tasksLength is equal to 1, then that could that either the asset task has not yet attempted to inject the dependencies for that asset, or that all of the dependencies have been loaded. To determine which one is the case, I had to add a dependenciesInjected variable. This defaults to false and is set to true once the dependencies for that asset have been injected into the AssetManager.\r\n\r\nIf the dependencies have already been injected, and the size of `tasks` == 1, that means that all of the dependencies have been loaded, so we use .9 as the progress estimation for the current asset. if the dependencies have not yet been injected, then the progress is estimated as 0.\r\n\r\nThe progress for the current asset is divided by the number of assets to load to calculate how much to add to `completedProgress` to estimate the actual current progress.\r\n```\r\nfloat progressForCurrentAsset = 0;\r\nif(tasksLength > 1) {\r\n\tprogressForCurrentAsset = 0.9f / (tasksLength * toLoad);\r\n} else if(tasksLength == 1) {\r\n\tAssetLoadingTask task = tasks.peek();\r\n\tif(task.dependenciesLoaded || task.dependenciesInjected) {\r\n\t\tprogressForCurrentAsset = 0.9f / toLoad;\r\n\t}\r\n}\r\nreturn Math.min(1, completedProgress + progressForCurrentAsset);\r\n```"}}