Added thread-safety to thumbnail request system.

Marked symbol requests as not being thread-safe.
Added icon to symbol editor
Made *.* actually register on *



git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@407 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
coppro
2007-05-21 16:11:38 +00:00
parent ad7a1a6506
commit 62ff837352
11 changed files with 75 additions and 15 deletions
+2
View File
@@ -84,6 +84,8 @@ class CardThumbnailRequest : public ThumbnailRequest {
parent->Refresh(false);
}
}
virtual bool threadSafe() const {return true;}
private:
String filename;
};
+1 -1
View File
@@ -29,7 +29,7 @@ class PackageList : public GalleryList {
}
/// Shows packages that match a specific patern
void showData(const String& pattern = _("*.*"));
void showData(const String& pattern = _("*"));
/// Clears this list
void clear();
+1 -1
View File
@@ -73,7 +73,7 @@ void ImagesExportWindow::onOk(wxCommandEvent&) {
ScriptP filename_script = parse(gs.images_export_filename, true);
// Select filename
String name = wxFileSelector(_TITLE_("export images"),_(""), _LABEL_("filename is ignored"),_(""),
_LABEL_("filename is ignored")+_("|*.*"), wxSAVE, this);
_LABEL_("filename is ignored")+_("|*"), wxSAVE, this);
if (name.empty()) return;
wxFileName fn(name);
// Export
+1
View File
@@ -54,6 +54,7 @@ SymbolWindow::SymbolWindow(Window* parent, const SymbolValueP& value, const SetP
void SymbolWindow::init(Window* parent, SymbolP symbol) {
Create(parent, wxID_ANY, _TITLE_("symbol editor"), wxDefaultPosition, wxSize(600,600), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
SetIcon(load_resource_icon(_("app")));
inSelectionEvent = false;
// Menu bar
+34 -10
View File
@@ -130,17 +130,41 @@ void ThumbnailThread::request(const ThumbnailRequestP& request) {
return;
}
}
request_names.insert(request);
// request generation
{
wxMutexLocker lock(mutex);
open_requests.push_back(request);
if (request->threadSafe()) {
request_names.insert(request);
// request generation
{
wxMutexLocker lock(mutex);
open_requests.push_back(request);
}
// is there a worker?
if (!worker) {
worker = new ThumbnailThreadWorker(this);
worker->Create();
worker->Run();
}
}
// is there a worker?
if (!worker) {
worker = new ThumbnailThreadWorker(this);
worker->Create();
worker->Run();
else {
Image img;
try {
img = request->generate();
} catch (const Error& e) {
handle_error(e, false, false);
} catch (...) {
}
// store in cache
if (img.Ok()) {
String filename = image_cache_dir() + safe_filename(request->cache_name) + _(".png");
img.SaveFile(filename, wxBITMAP_TYPE_PNG);
// set modification time
wxFileName fn(filename);
fn.SetTimes(0, &request->modified, 0);
}
{
wxMutexLocker lock(mutex);
closed_requests.push_back(make_pair(request,img));
completed.Signal();
}
}
}
+3
View File
@@ -31,6 +31,9 @@ class ThumbnailRequest : public IntrusivePtrVirtualBase {
virtual Image generate() = 0;
/// Store the thumbnail, called from the main thread
virtual void store(const Image&) = 0;
/// Can the thumbnail safely be generated from another thread?
virtual bool threadSafe() const = 0;
/// Object that requested the thumbnail
void* const owner;
+9 -1
View File
@@ -23,6 +23,9 @@ class ChoiceThumbnailRequest : public ThumbnailRequest {
ChoiceThumbnailRequest(ValueViewer* cve, int id, bool from_disk);
virtual Image generate();
virtual void store(const Image&);
bool isThreadSafe;
virtual bool threadSafe() const {return isThreadSafe;}
private:
StyleSheetP stylesheet;
int id;
@@ -37,7 +40,12 @@ ChoiceThumbnailRequest::ChoiceThumbnailRequest(ValueViewer* cve, int id, bool fr
)
, stylesheet(cve->viewer.stylesheet)
, id(id)
{}
{
ChoiceValueEditor& e = *(ChoiceValueEditor*)cve;
String name = cannocial_name_form(e.field().choices->choiceName(id));
ScriptableImage& img = e.style().choice_images[name];
isThreadSafe = img.threadSafe();
}
Image ChoiceThumbnailRequest::generate() {
ChoiceValueEditor& cve = *(ChoiceValueEditor*)owner;