Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/Loader.cpp
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | : func(func_), param(param_), description(desc_), | ||||
estimated_duration_ms(ms_) | estimated_duration_ms(ms_) | ||||
{ | { | ||||
} | } | ||||
}; | }; | ||||
typedef std::deque<LoadRequest> LoadRequests; | typedef std::deque<LoadRequest> LoadRequests; | ||||
static LoadRequests load_requests; | static LoadRequests load_requests; | ||||
// std::accumulate binary op; used by LDR_EndRegistering to sum up all | |||||
// estimated durations (for % progress calculation) | |||||
struct DurationAdder: public std::binary_function<double, const LoadRequest&, double> | |||||
{ | |||||
double operator()(double partial_result, const LoadRequest& lr) const | |||||
{ | |||||
return partial_result + lr.estimated_duration_ms*1e-3; | |||||
} | |||||
}; | |||||
// call before starting to register load requests. | // call before starting to register load requests. | ||||
// this routine is provided so we can prevent 2 simultaneous load operations, | // this routine is provided so we can prevent 2 simultaneous load operations, | ||||
// which is bogus. that can happen by clicking the load button quickly, | // which is bogus. that can happen by clicking the load button quickly, | ||||
// or issuing via console while already loading. | // or issuing via console while already loading. | ||||
void LDR_BeginRegistering() | void LDR_BeginRegistering() | ||||
{ | { | ||||
ENSURE(state == IDLE); | ENSURE(state == IDLE); | ||||
Show All 25 Lines | |||||
void LDR_EndRegistering() | void LDR_EndRegistering() | ||||
{ | { | ||||
ENSURE(state == REGISTERING); | ENSURE(state == REGISTERING); | ||||
ENSURE(!load_requests.empty()); | ENSURE(!load_requests.empty()); | ||||
state = FIRST_LOAD; | state = FIRST_LOAD; | ||||
estimated_duration_tally = 0.0; | estimated_duration_tally = 0.0; | ||||
task_elapsed_time = 0.0; | task_elapsed_time = 0.0; | ||||
total_estimated_duration = std::accumulate(load_requests.begin(), load_requests.end(), 0.0, DurationAdder()); | total_estimated_duration = std::accumulate(load_requests.begin(), load_requests.end(), 0.0, | ||||
[](double partial_result, const LoadRequest& lr) -> double { return partial_result + lr.estimated_duration_ms * 1e-3; }); | |||||
} | } | ||||
// immediately cancel this load; no further tasks will be processed. | // immediately cancel this load; no further tasks will be processed. | ||||
// used to abort loading upon user request or failure. | // used to abort loading upon user request or failure. | ||||
// note: no special notification will be returned by LDR_ProgressiveLoad. | // note: no special notification will be returned by LDR_ProgressiveLoad. | ||||
void LDR_Cancel() | void LDR_Cancel() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 186 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator