Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/Loader.cpp
/* Copyright (C) 2009 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
// holds all state for one load request; stored in queue. | // holds all state for one load request; stored in queue. | ||||
struct LoadRequest | struct LoadRequest | ||||
{ | { | ||||
// member documentation is in LDR_Register (avoid duplication). | // member documentation is in LDR_Register (avoid duplication). | ||||
LoadFunc func; | LoadFunc func; | ||||
void* param; | |||||
// MemFun_t<T> instance | |||||
std::shared_ptr<void> param; | |||||
// Translatable string shown to the player. | |||||
CStrW description; | CStrW description; | ||||
// rationale for storing as CStrW here: | |||||
// - needs to be WCS because it's user-visible and will be translated. | |||||
// - don't just store a pointer - the caller's string may be volatile. | |||||
// - the module interface must work in C, so we get/set as wchar_t*. | |||||
int estimated_duration_ms; | int estimated_duration_ms; | ||||
// LDR_Register gets these as parameters; pack everything together. | // LDR_Register gets these as parameters; pack everything together. | ||||
LoadRequest(LoadFunc func_, void* param_, const wchar_t* desc_, int ms_) | LoadRequest(LoadFunc func_, std::shared_ptr<void> param_, const wchar_t* desc_, int ms_) | ||||
: func(func_), param(param_), description(desc_), | : 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; | ||||
Show All 19 Lines | void LDR_BeginRegistering() | ||||
state = REGISTERING; | state = REGISTERING; | ||||
load_requests.clear(); | load_requests.clear(); | ||||
} | } | ||||
// register a task (later processed in FIFO order). | // register a task (later processed in FIFO order). | ||||
// <func>: function that will perform the actual work; see LoadFunc. | // <func>: function that will perform the actual work; see LoadFunc. | ||||
// <param>: (optional) parameter/persistent state; must be freed by func. | // <param>: (optional) parameter/persistent state. | ||||
// <description>: user-visible description of the current task, e.g. | // <description>: user-visible description of the current task, e.g. | ||||
// "Loading Textures". | // "Loading Textures". | ||||
// <estimated_duration_ms>: used to calculate progress, and when checking | // <estimated_duration_ms>: used to calculate progress, and when checking | ||||
// whether there is enough of the time budget left to process this task | // whether there is enough of the time budget left to process this task | ||||
// (reduces timeslice overruns, making the main loop more responsive). | // (reduces timeslice overruns, making the main loop more responsive). | ||||
void LDR_Register(LoadFunc func, void* param, const wchar_t* description, | void LDR_Register(LoadFunc func, std::shared_ptr<void> param, const wchar_t* description, | ||||
int estimated_duration_ms) | int estimated_duration_ms) | ||||
{ | { | ||||
ENSURE(state == REGISTERING); // must be called between LDR_(Begin|End)Register | ENSURE(state == REGISTERING); // must be called between LDR_(Begin|End)Register | ||||
const LoadRequest lr(func, param, description, estimated_duration_ms); | const LoadRequest lr(func, param, description, estimated_duration_ms); | ||||
load_requests.push_back(lr); | load_requests.push_back(lr); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator